/* ============ Mobile-first base ============ */
html, body {
    -webkit-text-size-adjust: 100%;
    overscroll-behavior-y: contain;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
}

a { text-decoration: none; }
a:hover { text-decoration: none; }

.btn-brand {
    background: var(--brand);
    color: white !important;
    border: none;
}
.btn-brand:hover, .btn-brand:focus { background: rgba(var(--brand-rgb), 0.9); color: white; }

.text-brand { color: var(--brand) !important; }
.bg-brand { background: var(--brand) !important; color: white; }
.border-brand { border-color: var(--brand) !important; }

/* ============ Login page ============ */
.login-card {
    max-width: 400px;
    margin: 5vh auto 20px;
    padding: 32px 24px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 4px 16px rgba(0,0,0,.08);
}
.login-logo {
    text-align: center;
    font-size: 48px;
    color: var(--brand);
    margin-bottom: 16px;
}

/* ============ Order list ============ */
.search-box {
    position: sticky;
    top: 56px;
    z-index: 100;
    background: white;
    padding: 12px;
    border-bottom: 1px solid #dee2e6;
}

.order-card {
    background: white;
    border-radius: 12px;
    padding: 14px 16px;
    margin: 0 12px 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
    border-left: 4px solid var(--brand);
    transition: transform .1s, box-shadow .15s;
}
.order-card:active {
    transform: scale(0.98);
    box-shadow: 0 1px 6px rgba(0,0,0,.12);
}
.order-card .order-code {
    font-weight: 600;
    font-size: 15px;
    color: var(--brand);
    word-break: break-all;
}
.order-card .order-meta {
    font-size: 12.5px;
    color: #6c757d;
    margin-top: 4px;
}
.order-card .order-meta i { width: 14px; }
.order-card .badges { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 4px; }
.order-card .badges .badge {
    font-weight: 500;
    font-size: 11px;
}

/* ============ Files grid ============ */
.order-summary {
    background: white;
    padding: 12px 16px;
    margin-bottom: 8px;
    border-bottom: 1px solid #dee2e6;
}
.order-summary .title { font-weight: 600; color: var(--brand); }
.order-summary .meta { font-size: 12.5px; color: #6c757d; }

.file-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
    padding: 10px;
}
@media (min-width: 768px) {
    .file-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    }
}

.file-card {
    background: white;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
    display: flex;
    flex-direction: column;
    cursor: pointer;
    transition: transform .12s;
}
.file-card:active { transform: scale(0.97); }
.file-card .thumb {
    width: 100%;
    aspect-ratio: 1;
    background: #f1f3f5;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6c757d;
    font-size: 48px;
    position: relative;
}
.file-card .thumb img {
    width: 100%; height: 100%; object-fit: cover;
    /* Khi img fail load (network/SFTP issue), browser hiện alt text -
       set text-indent để ẩn đi (UI sạch hơn so với thấy GUID dài) */
    text-indent: -9999px;
    color: transparent;
    font-size: 0;
}
.file-card .badge-signed {
    position: absolute;
    bottom: 6px; right: 6px;
    background: #28a745;
    color: white;
    width: 22px; height: 22px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    border: 2px solid white;
    box-shadow: 0 1px 2px rgba(0,0,0,.2);
    font-size: 11px;
}
.file-card .info {
    padding: 8px 10px;
}
.file-card .info .name {
    font-size: 12.5px;
    font-weight: 500;
    color: #1f2937;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-height: 1.3;
    min-height: 2.6em;
}
.file-card .info .meta {
    font-size: 11px;
    color: #6c757d;
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.file-card .info .meta .ext {
    background: #e7eaf3;
    color: var(--brand);
    padding: 1px 6px;
    border-radius: 3px;
    font-weight: 600;
    text-transform: uppercase;
}

/* ============ Viewer page ============ */
.viewer-shell {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    background: #2c2c2c;
    color: white;
}

.viewer-header {
    background: var(--brand);
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 48px;
}
.viewer-header .btn-icon {
    background: transparent;
    border: 0;
    color: white;
    padding: 6px 8px;
    border-radius: 6px;
    font-size: 1.3rem;
}
.viewer-header .btn-icon:hover { background: rgba(255,255,255,.15); }
.viewer-header .title {
    flex: 1;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Prev/Next nav - hiển thị giữa title và nút download */
.viewer-header .viewer-nav {
    display: flex;
    align-items: center;
    gap: 2px;
    background: rgba(255,255,255,.1);
    border-radius: 8px;
    padding: 2px;
    margin: 0 6px;
}
.viewer-header .viewer-nav .nav-counter {
    color: white;
    font-size: 12px;
    padding: 0 8px;
    min-width: 50px;
    text-align: center;
    user-select: none;
    font-variant-numeric: tabular-nums;
}
.viewer-header .btn-icon.disabled {
    opacity: 0.35;
    cursor: not-allowed;
    pointer-events: none;
}

@media (max-width: 480px) {
    /* Mobile: collapse title hơn để nav vẫn lên header */
    .viewer-header .title { font-size: 13px; }
    .viewer-header .viewer-nav { margin: 0 4px; }
    .viewer-header .viewer-nav .nav-counter {
        font-size: 11px;
        padding: 0 4px;
        min-width: 40px;
    }
}

.viewer-toolbar {
    background: #1f1f1f;
    padding: 6px 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
    border-bottom: 1px solid #404040;
}
.viewer-toolbar .btn-tool {
    background: transparent;
    border: 1px solid #555;
    color: white;
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.viewer-toolbar .btn-tool.active {
    background: var(--brand);
    border-color: var(--brand);
}
.viewer-toolbar .btn-tool:hover { background: rgba(255,255,255,.1); }
.viewer-toolbar .btn-tool.active:hover { background: rgba(var(--brand-rgb), 0.85); }
.viewer-toolbar .separator { width: 1px; height: 20px; background: #555; margin: 0 4px; }

.viewer-content {
    flex: 1;
    overflow: hidden;
    position: relative;
    background: #2c2c2c;
}

/* Image mode */
.viewer-image-wrap {
    width: 100%;
    height: 100%;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #2c2c2c;
}
.viewer-image-wrap .image-canvas-stack {
    position: relative;
    display: inline-block;
}
.viewer-image-wrap img {
    display: block;
    max-width: none;
    user-select: none;
    pointer-events: none;
}

/* Annotation canvas overlay - đặt trên image hoặc PDF page */
.annotation-canvas {
    position: absolute;
    inset: 0;
    cursor: crosshair;
    touch-action: none;
}
.annotation-canvas.pan-mode {
    cursor: grab;
    pointer-events: none;
}

/* PDF mode - iframe full size */
.viewer-pdf-frame {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
}

/* Unsupported */
.viewer-unsupported {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 24px;
    text-align: center;
}
.viewer-unsupported .icon-big {
    font-size: 64px;
    color: #6c757d;
    margin-bottom: 16px;
}

/* Pagination */
.pager {
    display: flex;
    justify-content: center;
    gap: 8px;
    padding: 16px;
}

/* Empty state */
.empty-state {
    padding: 40px 24px;
    text-align: center;
    color: #6c757d;
}
.empty-state .icon-big { font-size: 56px; margin-bottom: 12px; opacity: 0.5; }

/* Bottom safe area iOS */
@supports (padding: max(0px)) {
    .viewer-toolbar {
        padding-bottom: max(6px, env(safe-area-inset-bottom));
    }
}
