/* Paddy Printer - Global */
:root {
    --primary: #e0156f;
    --primary-hover: #e0156f;
    --border: #e5e7eb;
    --bg: #f8fafc;
    --text: #1e293b;
    --error: #dc2626;
    --success: #16a34a;
}

* {
    box-sizing: border-box;
}
body {
    font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

/* Header */
.header {
    background: #fff;
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 1rem;
}
.header-inner {
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}
.header .back {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}
.header .back:hover {
    text-decoration: underline;
}
.header h1 {
    margin: 0;
    font-size: 1.25rem;
    flex: 1;
}
.header .user {
    color: #64748b;
    font-size: 0.9rem;
}
.header .btn {
    margin-left: auto;
}

/* Main */
.main {
    max-width: 900px;
    margin: 0 auto;
    padding: 1.5rem 1rem;
}
.main h2 {
    margin-top: 0;
    margin-bottom: 0.5rem;
}
.hint {
    color: #64748b;
    margin-bottom: 1.5rem;
    font-size: 0.95rem;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    text-decoration: none;
    border: none;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-primary {
    background: var(--primary);
    color: #fff;
}
.btn-primary:hover {
    background: var(--primary-hover);
}
.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--primary);
}
.btn-outline:hover {
    background: rgba(37, 99, 235, 0.08);
}

/* Login */
.page-login {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
}
.login-box {
    background: #fff;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    width: 100%;
    max-width: 360px;
}
.login-box h1 {
    margin: 0 0 0.25rem;
    font-size: 1.5rem;
}
.login-box .subtitle {
    color: #64748b;
    margin-bottom: 1.5rem;
}
.login-box label {
    display: block;
    margin-bottom: 0.35rem;
    font-weight: 500;
    font-size: 0.9rem;
}
.login-box input {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    margin-bottom: 1rem;
}
.login-box button {
    width: 100%;
    padding: 0.75rem;
    margin-top: 0.5rem;
}

/* Alerts */
.alert {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
}
.alert-error {
    background: #fef2f2;
    color: var(--error);
}
.alert-success {
    background: #f0fdf4;
    color: var(--success);
}

/* Dashboard - Outlet grid */
.outlet-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}
.outlet-card {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 120px;
    background: #fff;
    border: 2px solid var(--border);
    border-radius: 12px;
    text-decoration: none;
    color: var(--text);
    font-weight: 600;
    font-size: 1.1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.outlet-card:hover {
    border-color: var(--primary);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.15);
}

.login-header .logo img {
    width: 180px;
}

/* Frames - Frame list */
.frame-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
}
.frame-card {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    min-height: 0;
    padding: 0;
    overflow: hidden;
    background: #fff;
    border: 2px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    text-align: center;
    padding-top: 10px;
}
.frame-card:hover {
    border-color: var(--primary);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.15);
}
.frame-card-preview {
    display: block;
    width: 100%;
    aspect-ratio: 3/4;
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    background-color: #f1f5f9;
}
.frame-card .frame-name {
    font-weight: 600;
    margin: 0.75rem 0.5rem 0.25rem;
}
.frame-card .frame-slots {
    font-size: 0.85rem;
    color: #64748b;
    margin-bottom: 0.75rem;
}
.frame-name {
    font-weight: 600;
    margin-bottom: 0.25rem;
}
.frame-slots {
    font-size: 0.85rem;
    color: #64748b;
}

/* QR section */
.qr-section {
    display: flex;
    flex-wrap: wrap;
    gap: 2rem;
    align-items: flex-start;
    background: #fff;
    padding: 1.5rem;
    border-radius: 12px;
    border: 1px solid var(--border);
}
.qr-box {
    text-align: center;
}
.qr-image {
    display: block;
    border-radius: 8px;
    max-width: 100%;
    height: auto;
}
.qr-label {
    margin-top: 0.75rem;
    font-size: 0.9rem;
    color: #64748b;
    max-width: 100%;
}
.qr-local-hint {
    margin-top: 0.5rem;
    font-size: 0.8rem;
    color: #0ea5e9;
    max-width: 280px;
}
.qr-local-hint code {
    display: block;
    margin-top: 0.25rem;
    word-break: break-all;
    font-size: 0.75rem;
}
.qr-actions {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.frame-info {
    margin: 0;
    font-size: 0.95rem;
}
.upload-status {
    margin-top: 1rem;
    min-height: 1.5rem;
}
.upload-status .badge {
    display: inline-block;
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    font-size: 0.9rem;
}
.upload-status .badge.wait {
    background: #fef3c7;
    color: #92400e;
}
.upload-status .badge.ok {
    background: #d1fae5;
    color: #065f46;
}

.frame-selected-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}
.frame-selected-actions .frame-info {
    margin: 0;
    flex: 1;
    min-width: 180px;
}

/* Modal popup QR */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    visibility: hidden;
    opacity: 0;
    transition: visibility 0.2s, opacity 0.2s;
}
.modal.modal-open {
    visibility: visible;
    opacity: 1;
}
.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
}
.modal-content {
    position: relative;
    background: #fff;
    border-radius: 12px;
    padding: 1.5rem;
    max-width: 360px;
    width: 100%;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}
.modal-close {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    width: 2rem;
    height: 2rem;
    border: none;
    background: transparent;
    font-size: 1.5rem;
    line-height: 1;
    color: #64748b;
    cursor: pointer;
    padding: 0;
    border-radius: 4px;
}
.modal-close:hover {
    color: #1e293b;
    background: #f1f5f9;
}
.modal-title {
    margin: 0 0 1rem;
    font-size: 1.15rem;
}
.modal-content .qr-box {
    margin: 0 auto 1rem;
}
.modal-content .qr-image {
    margin: 0 auto;
}
.qr-loading {
    display: block;
    text-align: center;
    padding: 2rem;
    color: #64748b;
}
.modal-hint {
    margin: 1rem 0 0;
    font-size: 0.85rem;
    color: #64748b;
    text-align: center;
}

/* Upload page (mobile) */
.page-upload {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.upload-container {
    background: #fff;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    width: 100%;
    max-width: 400px;
}
.upload-container h1 {
    margin: 0 0 0.5rem;
    font-size: 1.5rem;
}
.upload-hint {
    color: #64748b;
    margin-bottom: 0.75rem;
    font-size: 0.95rem;
}
.upload-count {
    margin: 0 0 1rem;
    font-size: 0.9rem;
    color: #475569;
}
.file-limit-hint {
    margin: 0.5rem 0 0;
    font-size: 0.85rem;
    color: #64748b;
}
.file-limit-hint.limit-warn {
    color: #b45309;
    font-weight: 500;
}
.photo-preview-list {
    margin: 1rem 0;
    padding: 0;
}
.photo-preview-title {
    margin: 0 0 0.5rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: #1e293b;
}
.photo-preview-list .photo-preview-item {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.25rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}
.photo-preview-list .photo-preview-item:last-child {
    border-bottom: none;
}
.photo-preview-list .photo-preview-item img {
    width: 56px;
    height: 56px;
    object-fit: cover;
    border-radius: 8px;
    flex-shrink: 0;
}
.photo-preview-item-wrap {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
    min-width: 0;
}
.photo-preview-item .photo-item-delete {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: #fef2f2;
    color: #b91c1c;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.photo-preview-item .photo-item-delete:hover {
    background: #fecaca;
}
.photo-preview-item .upload-progress-wrap {
    margin-top: 0.35rem;
    height: 6px;
    background: #e2e8f0;
    border-radius: 3px;
    overflow: hidden;
}
.photo-preview-item .upload-progress-bar {
    height: 100%;
    width: 0%;
    background: #86efac;
    border-radius: 3px;
    transition: width 0.15s ease;
}
.upload-container input[type="file"] {
    position: absolute;
    width: 0.1px;
    height: 0.1px;
    opacity: 0;
    overflow: hidden;
    z-index: -1;
}
.btn-upload {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    background: #e0e7ff;
    color: var(--primary);
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    margin-bottom: 1rem;
    text-align: center;
    width: 100%;
}
.btn-upload:hover {
    background: #c7d2fe;
}
.upload-container .btn-primary {
    margin-top: 0.5rem;
    width: 100%;
    padding: 15px;
}
.done-msg {
    margin-top: 1rem;
    color: var(--success);
    font-weight: 500;
}

/* Preview page */
.preview-two-cols {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 1.5rem;
    align-items: start;
    margin-bottom: 1.5rem;
}
@media (max-width: 600px) {
    .preview-two-cols {
        grid-template-columns: 1fr;
    }
    .preview-two-cols .preview-frame-wrap {
        max-width: 100%;
        width: 100%;
    }
}
.preview-two-cols .preview-frame-wrap {
    max-width: 80%;
    width: 80%;
}
.preview-frame.preview-frame-small,
#previewFrame.preview-frame-small {
    max-width: 80%;
    width: 80%;
}
.preview-frame.preview-frame-small.frame-with-image,
#previewFrame.preview-frame-small.frame-with-image {
    max-width: 80%;
    width: 80%;
}
.preview-layout {
    background: #fff;
    padding: 1.25rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    margin-bottom: 0;
    min-width: 200px;
}
.preview-two-cols .preview-layout {
    margin-bottom: 0;
}
.preview-layout h3,
.preview-frame-wrap h3 {
    margin: 0 0 1rem;
    font-size: 1rem;
}
.assign-form {
    display: grid;
    gap: 0.75rem;
}
.assign-row {
    display: flex;
    align-items: center;
    gap: 1rem;
}
.assign-row label {
    min-width: 60px;
    font-weight: 500;
}
.slot-select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    flex: 1;
    max-width: 200px;
}

/* Tablet: 768px - 1024px */
@media (min-width: 768px) and (max-width: 1024px) {

    .upload-container {
        max-width: 460px;
        padding: 2.25rem;
    }
    .upload-container h1 {
        font-size: 1.4rem;
    }
    .upload-hint {
        font-size: 1rem;
    }
    .photo-preview-list .photo-preview-item img {
        width: 64px;
        height: 64px;
    }
    .main {
        padding: 1.5rem 1.25rem;
    }
    .preview-two-cols {
        gap: 1.25rem;
    }
    .preview-layout {
        padding: 1.5rem;
        min-width: 220px;
    }
    .preview-layout h3,
    .preview-frame-wrap h3 {
        font-size: 1.05rem;
    }
    .assign-row label {
        min-width: 72px;
        font-size: 0.95rem;
    }
    .slot-select {
        padding: 0.6rem 0.85rem;
        max-width: 220px;
        font-size: 1rem;
    }
    .btn-print {
        padding: 0.85rem 2rem;
        font-size: 1.05rem;
    }
    .modal-content {
        max-width: 400px;
    }
}

/* Mobile kecil */
@media (max-width: 480px) {
    .upload-container {
        padding: 1.5rem 1.25rem;
    }
    .upload-container h1 {
        font-size: 1.3rem;
    }
    .assign-row {
        flex-direction: column;
        align-items: stretch;
        gap: 0.35rem;
    }
    .assign-row label {
        min-width: 0;
    }
    .slot-select {
        max-width: 100%;
    }
}
.preview-frame-wrap {
    background: #fff;
    padding: 1.25rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    margin-bottom: 1.5rem;
}
.preview-two-cols .preview-frame-wrap {
    margin-bottom: 0;
}
.preview-frame {
    max-width: 100%;
    overflow: auto;
}
.print-form-below-slots {
    margin-top: 1.25rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border, #e2e8f0);
}
.btn-print {
    font-size: 1.1rem;
    padding: 0.75rem 2rem;
}

/* Frame layouts - frame PNG + overlay slot */
/* Ukuran cetak: Canon Selphy CP1500 postcard 100x148mm (4R) */
.frame-print {
    background: #fff;
    border: 1px solid var(--border);
}
.frame-print.frame-with-image {
    position: relative;
    max-width: 100%;
    width: 100%;
    margin: 0 auto;
    aspect-ratio: 100 / 148;
}
.frame-print.frame-with-image .frame-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
    z-index: 1;
    display: block;
    pointer-events: none;
}
.frame-print.frame-with-image .frame-slots {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 0;
    display: grid;
    gap: 2%;
    padding: 4%;
    box-sizing: border-box;
}
/* Posisi custom: slot mengikuti area transparan di PNG (top/left/width/height dari config) */
.frame-print.frame-with-positions .frame-slots {
    display: block;
    padding: 0;
    gap: 0;
}
.frame-print.frame-with-positions .slot {
    position: absolute;
    box-sizing: border-box;
    overflow: hidden;
    background: transparent;
}
/* Hanya slot tanpa posisi custom yang pakai relative (grid); yang pakai positions harus absolute */
.frame-print.frame-with-image:not(.frame-with-positions) .slot {
    position: relative;
    overflow: hidden;
    background: rgba(255,255,255,0.15);
    border-radius: 2px;
}
.frame-print.frame-with-image .slot-inner {
    width: 100%;
    height: 100%;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.frame-print.frame-with-image .slot-inner img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
/* Fallback grid bila frame tidak punya positions */
.frame-grid-2 .frame-slots { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr; }
.frame-grid-3 .frame-slots { grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 1fr; }
.frame-grid-4 .frame-slots { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.frame-grid-5 .frame-slots { grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 1fr 1fr; }
.frame-grid-6 .frame-slots { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr 1fr; }
.frame-grid-7 .frame-slots,
.frame-grid-8 .frame-slots,
.frame-grid-9 .frame-slots,
.frame-grid-10 .frame-slots,
.frame-grid-11 .frame-slots,
.frame-grid-12 .frame-slots { grid-template-columns: 1fr 1fr 1fr; grid-template-rows: repeat(4, 1fr); }
