/* Page: documents.html — Document Management */

    /* ═══ PAGE BODY ═══ */
    .db-page { max-width: 1400px; margin: 0 auto; padding: var(--s8); }

    /* ── STATS ROW ── */
    .docs-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s4); margin-bottom: var(--s6); }
    .docs-stat { background: var(--white); border: 1px solid var(--border); border-radius: var(--r-xl); padding: var(--s5); transition: box-shadow var(--t-base); }
    .docs-stat:hover { box-shadow: var(--sh-sm); }
    .docs-stat__label { font-size: var(--t-xs); font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--text-m); margin-bottom: var(--s2); }
    .docs-stat__val { font-family: var(--font-d); font-size: var(--t-2xl); font-weight: 700; color: var(--ink); letter-spacing: -0.02em; line-height: 1; }
    .docs-stat__val.blue  { color: var(--blue); }
    .docs-stat__val.green { color: var(--ok); }
    .docs-stat__val.amber { color: var(--amber); }
    .docs-stat__sub { font-size: var(--t-xs); color: var(--text-m); margin-top: var(--s1); display: flex; align-items: center; gap: var(--s2); }

    /* ── CONTROLS BAR ── */
    .docs-controls { display: flex; align-items: center; gap: var(--s3); margin-bottom: var(--s5); flex-wrap: wrap; }
    .docs-search { flex: 1; min-width: 220px; position: relative; }
    .docs-search__input { width: 100%; border: 1.5px solid var(--border); border-radius: var(--r-pill); padding: var(--s3) var(--s4) var(--s3) 36px; font-size: var(--t-sm); outline: none; transition: border-color var(--t-fast); background: var(--white); color: var(--ink); }
    .docs-search__input:focus { border-color: var(--blue); }
    .docs-search__icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-m); pointer-events: none; }

    .docs-filter { display: flex; gap: var(--s2); flex-wrap: wrap; }
    .docs-filter-btn { border: 1.5px solid var(--border); border-radius: var(--r-pill); padding: var(--s2) var(--s4); font-size: var(--t-xs); font-weight: 600; cursor: pointer; background: var(--white); color: var(--text-m); transition: all var(--t-fast); white-space: nowrap; }
    .docs-filter-btn:hover { border-color: var(--blue); color: var(--blue); }
    .docs-filter-btn.active { border-color: var(--blue); background: var(--blue); color: var(--white); }

    .docs-view-toggle { display: flex; border: 1.5px solid var(--border); border-radius: var(--r-lg); overflow: hidden; flex-shrink: 0; }
    .docs-view-btn { padding: var(--s2) var(--s3); background: var(--white); border: none; cursor: pointer; color: var(--text-m); transition: all var(--t-fast); display: flex; align-items: center; gap: var(--s2); font-size: var(--t-xs); font-weight: 600; }
    .docs-view-btn.active { background: var(--blue); color: var(--white); }
    .docs-view-btn + .docs-view-btn { border-left: 1.5px solid var(--border); }
    .docs-view-btn.active + .docs-view-btn { border-left-color: var(--blue); }

    /* ── UPLOAD BUTTON ── */
    .docs-upload-btn { flex-shrink: 0; }

    /* ── LIST VIEW TABLE ── */
    .docs-table-wrap { background: var(--white); border: 1px solid var(--border); border-radius: var(--r-2xl); overflow: hidden; margin-bottom:5rem;}
    .docs-table { width: 100%; border-collapse: collapse; }
    .docs-table thead th { padding: var(--s3) var(--s5); text-align: left; font-size: var(--t-xs); font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--text-m); background: var(--off); border-bottom: 1px solid var(--border); white-space: nowrap; }
    .docs-table thead th:first-child { border-radius: var(--r-lg) 0 0 0; }
    .docs-table thead th.sortable { cursor: pointer; user-select: none; }
    .docs-table thead th.sortable:hover { color: var(--blue); }
    .docs-table thead th .sort-arrow { margin-left: 4px; opacity: .4; }
    .docs-table thead th.sort-active .sort-arrow { opacity: 1; color: var(--blue); }
    .docs-table tbody tr { border-bottom: 1px solid var(--border); transition: background var(--t-fast); cursor: pointer; }
    .docs-table tbody tr:last-child { border-bottom: none; }
    .docs-table tbody tr:hover { background: var(--off); }
    .docs-table tbody td { padding: var(--s4) var(--s5); vertical-align: middle; }

    .doc-row__icon-wrap { width: 40px; height: 40px; border-radius: var(--r-lg); display: flex; align-items: center; justify-content: center; font-size: 1.2rem; flex-shrink: 0; border: 1px solid var(--border); }
    .doc-row__icon-wrap.pdf  { background: rgba(239,68,68,.07);  border-color: rgba(239,68,68,.2); }
    .doc-row__icon-wrap.img  { background: rgba(37,99,235,.07);  border-color: rgba(37,99,235,.2); }
    .doc-row__icon-wrap.doc  { background: rgba(5,150,105,.07);  border-color: rgba(5,150,105,.2); }
    .doc-row__icon-wrap.gen  { background: var(--off); }

    .doc-row__name { font-size: var(--t-sm); font-weight: 700; color: var(--ink); margin-bottom: 2px; }
    .doc-row__type { font-size: var(--t-xs); color: var(--text-m); }
    .doc-row__date { font-size: var(--t-sm); color: var(--ink-3); white-space: nowrap; }
    .doc-row__date span { display: block; font-size: var(--t-xs); color: var(--text-m); }
    .doc-row__size { font-size: var(--t-xs); color: var(--text-m); white-space: nowrap; }

    /* AI Summary in table */
    .ai-summary-cell { max-width: 280px; }
    .ai-summary-cell__text { font-size: var(--t-xs); color: var(--text-s); line-height: 1.55; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
    .ai-summary-cell__processing { display: flex; align-items: center; gap: var(--s2); font-size: var(--t-xs); color: var(--blue); font-weight: 600; }
    .ai-pulse { width: 6px; height: 6px; border-radius: 50%; background: var(--blue); animation: aiPulse 1.2s ease-in-out infinite; }
    @keyframes aiPulse { 0%,100%{opacity:1;transform:scale(1)} 50%{opacity:.4;transform:scale(.6)} }

    .ai-badge { display: inline-flex; align-items: center; gap: 4px; font-size: 10px; font-weight: 700; background: linear-gradient(135deg, var(--blue) 0%, #7C3AED 100%); color: white; padding: 2px 7px; border-radius: var(--r-pill); letter-spacing: .04em; }
    .ai-badge svg { width: 8px; height: 8px; }

    .doc-actions { display: flex; align-items: center; gap: var(--s2); }
    .doc-action-btn { width: 30px; height: 30px; border-radius: var(--r-md); border: 1.5px solid var(--border); background: var(--white); display: flex; align-items: center; justify-content: center; cursor: pointer; transition: all var(--t-fast); flex-shrink: 0; }
    .doc-action-btn:hover { border-color: var(--blue); background: var(--blue-pale); }
    .doc-action-btn svg { width: 13px; height: 13px; color: var(--text-m); }
    .doc-action-btn:hover svg { color: var(--blue); }

    /* ── GRID VIEW ── */
    .docs-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--s5); }
    .doc-card { background: var(--white); border: 1.5px solid var(--border); border-radius: var(--r-2xl); overflow: hidden; transition: all var(--t-base); cursor: pointer; }
    .doc-card:hover { box-shadow: var(--sh-sm); border-color: var(--blue-light); transform: translateY(-1px); }

    .doc-card__preview { height: 140px; background: var(--off); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: center; position: relative; overflow: hidden; }
    .doc-card__preview-icon { font-size: 3rem; opacity: .35; }
    .doc-card__preview-img { width: 100%; height: 100%; object-fit: cover; }
    .doc-card__preview-overlay { position: absolute; inset: 0; background: linear-gradient(to bottom, transparent 40%, rgba(0,0,0,.35) 100%); opacity: 0; transition: opacity var(--t-base); }
    .doc-card:hover .doc-card__preview-overlay { opacity: 1; }
    .doc-card__preview-actions { position: absolute; bottom: var(--s3); right: var(--s3); display: flex; gap: var(--s2); opacity: 0; transform: translateY(4px); transition: all var(--t-base); }
    .doc-card:hover .doc-card__preview-actions { opacity: 1; transform: translateY(0); }
    .doc-card__preview-btn { width: 28px; height: 28px; background: rgba(255,255,255,.95); border-radius: var(--r-md); display: flex; align-items: center; justify-content: center; border: none; cursor: pointer; }
    .doc-card__preview-btn svg { width: 13px; height: 13px; color: var(--ink); }

    .doc-card__type-pill { position: absolute; top: var(--s3); left: var(--s3); background: rgba(255,255,255,.95); border: 1px solid var(--border); border-radius: var(--r-pill); padding: 3px 8px; font-size: 10px; font-weight: 700; color: var(--text-m); text-transform: uppercase; letter-spacing: .06em; backdrop-filter: blur(4px); }

    .doc-card__body { padding: var(--s4) var(--s5); }
    .doc-card__name { font-size: var(--t-sm); font-weight: 700; color: var(--ink); margin-bottom: var(--s1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .doc-card__meta { display: flex; align-items: center; gap: var(--s3); margin-bottom: var(--s3); flex-wrap: wrap; }
    .doc-card__date { font-size: var(--t-xs); color: var(--text-m); }

    .doc-card__ai { background: var(--off); border-radius: var(--r-lg); padding: var(--s3); margin-bottom: var(--s3); }
    .doc-card__ai-label { display: flex; align-items: center; gap: var(--s2); margin-bottom: var(--s2); }
    .doc-card__ai-text { font-size: var(--t-xs); color: var(--text-s); line-height: 1.55; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
    .doc-card__ai-text.processing { color: var(--blue); animation: aiTextFade 2s ease-in-out infinite; }
    @keyframes aiTextFade { 0%,100%{opacity:1} 50%{opacity:.5} }

    .doc-card__footer { display: flex; align-items: center; justify-content: space-between; }
    .doc-card__size { font-size: var(--t-xs); color: var(--text-m); }

    /* ── EMPTY STATE ── */
    .docs-empty { text-align: center; padding: var(--s8) var(--s6); }
    .docs-empty__icon { font-size: 3rem; margin-bottom: var(--s4); opacity: .4; }
    .docs-empty__title { font-family: var(--font-d); font-size: var(--t-xl); font-weight: 700; color: var(--ink); margin-bottom: var(--s2); }
    .docs-empty__sub { font-size: var(--t-sm); color: var(--text-m); margin-bottom: var(--s5); max-width: 360px; margin-left: auto; margin-right: auto; }

    /* ── UPLOAD MODAL ── */
    .modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); backdrop-filter: blur(4px); z-index: 1000; display: flex; align-items: center; justify-content: center; padding: var(--s5); opacity: 0; pointer-events: none; transition: opacity var(--t-base); }
    .modal-overlay.open { opacity: 1; pointer-events: all; }
    .modal-box { background: var(--white); border-radius: var(--r-2xl); width: 100%; max-width: 540px; overflow: hidden; transform: translateY(16px) scale(.98); transition: transform var(--t-base); box-shadow: 0 24px 64px rgba(0,0,0,.2); }
    .modal-overlay.open .modal-box { transform: translateY(0) scale(1); }
    .modal-head { padding: var(--s5) var(--s6); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
    .modal-head__title { font-family: var(--font-d); font-size: var(--t-xl); font-weight: 700; color: var(--ink); }
    .modal-close { width: 32px; height: 32px; border-radius: 50%; border: 1.5px solid var(--border); background: var(--white); display: flex; align-items: center; justify-content: center; cursor: pointer; transition: all var(--t-fast); }
    .modal-close:hover { background: var(--off); }
    .modal-body { padding: var(--s6); }

    .upload-zone-main { border: 2px dashed var(--border-hi); border-radius: var(--r-xl); padding:var(--s8) 15% var(--s8) var(--s6); text-align: center; cursor: pointer; transition: all var(--t-base); position: relative; }
    .upload-zone-main:hover, .upload-zone-main.dragging { border-color: var(--blue); background: var(--blue-pale); }
    .upload-zone-main__icon { font-size: 2.5rem; margin-bottom: var(--s3);float:left; }
    .upload-zone-main__title { font-size: var(--t-md); font-weight: 700; color: var(--ink); margin-bottom: var(--s2); }
    .upload-zone-main__sub { font-size: var(--t-sm); color: var(--text-m); line-height: 1.6; }
    .upload-zone-main__types { display: flex; gap: var(--s2); justify-content: center; margin-top: var(--s3); flex-wrap: wrap; }
    .upload-type-tag { background: var(--off); border: 1px solid var(--border); border-radius: var(--r-pill); padding: 2px 10px; font-size: 11px; font-weight: 600; color: var(--text-m); }
    #fileInputHidden { display: none; }

    .doc-type-select { margin-top: var(--s4); }
    .doc-type-select__label { font-size: var(--t-xs); font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--text-m); margin-bottom: var(--s2); display: block; }
    .doc-type-select__grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s2); }
    .doc-type-opt {     height: 50px;line-height: 1rem;border: 1.5px solid var(--border); border-radius: var(--r-lg); padding: var(--s3); cursor: pointer; text-align: center; transition: all var(--t-fast); }
    .doc-type-opt:hover { border-color: var(--blue-light); }
    .doc-type-opt.selected { border-color: var(--blue); background: var(--blue-pale); }
    .doc-type-opt__icon { font-size: 1.2rem; margin-bottom: 3px; float:left;}
    .doc-type-opt__label { font-size: var(--t-xs); font-weight: 600; color: var(--ink); line-height: 2; }

    .modal-foot { padding: var(--s4) var(--s6); border-top: 1px solid var(--border); display: flex; gap: var(--s3); justify-content: flex-end; background: var(--off); }

    /* ── PROCESSING OVERLAY ── */
    .ai-processing { display: none; flex-direction: column; align-items: center; justify-content: center; padding: var(--s8) var(--s6); text-align: center; }
    .ai-processing.show { display: flex; }
    .ai-processing__orb { width: 72px; height: 72px; border-radius: 50%; background: linear-gradient(135deg, var(--blue) 0%, #7C3AED 100%); display: flex; align-items: center; justify-content: center; margin-bottom: var(--s4); position: relative; }
    .ai-processing__orb::before { content: ''; position: absolute; inset: -6px; border-radius: 50%; border: 2px solid transparent; background: linear-gradient(135deg, var(--blue), #7C3AED) border-box; -webkit-mask: linear-gradient(#fff 0 0) padding-box, linear-gradient(#fff 0 0); -webkit-mask-composite: destination-out; mask-composite: exclude; animation: orbSpin 2s linear infinite; }
    @keyframes orbSpin { to { transform: rotate(360deg); } }
    .ai-processing__title { font-size: var(--t-lg); font-weight: 700; color: var(--ink); margin-bottom: var(--s2); }
    .ai-processing__steps { display: flex; flex-direction: column; gap: var(--s2); width: 100%; max-width: 300px; }
    .ai-step { display: flex; align-items: center; gap: var(--s3); font-size: var(--t-xs); color: var(--text-m); }
    .ai-step__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border); flex-shrink: 0; transition: background var(--t-base); }
    .ai-step.done .ai-step__dot { background: var(--ok); }
    .ai-step.active .ai-step__dot { background: var(--blue); animation: aiPulse 1s infinite; }
    .ai-step.done { color: var(--ok); font-weight: 600; }
    .ai-step.active { color: var(--blue); font-weight: 600; }

    /* ── DOCUMENT DETAIL PANEL ── */
    .doc-detail-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); backdrop-filter: blur(3px); z-index: 999; opacity: 0; pointer-events: none; transition: opacity var(--t-base); }
    .doc-detail-overlay.open { opacity: 1; pointer-events: all; }
    .doc-detail-panel { position: fixed; top: 0; right: 0; bottom: 0; width: 480px; max-width: 100vw; background: var(--white); z-index: 1001; transform: translateX(100%); transition: transform var(--t-slow); overflow-y: auto; box-shadow: -8px 0 40px rgba(0,0,0,.15); display: flex; flex-direction: column; }
    .doc-detail-panel.open { transform: translateX(0); }
    .doc-detail-panel::-webkit-scrollbar { width: 3px; }
    .doc-detail-panel::-webkit-scrollbar-thumb { background: var(--border-hi); }

    .ddp-head { padding: var(--s5) var(--s6); border-bottom: 1px solid var(--border); display: flex; align-items: flex-start; gap: var(--s4); position: sticky; top: 0; background: var(--white); z-index: 2; }
    .ddp-head__icon { width: 48px; height: 48px; border-radius: var(--r-xl); display: flex; align-items: center; justify-content: center; font-size: 1.4rem; flex-shrink: 0; border: 1px solid var(--border); background: var(--off); }
    .ddp-head__info { flex: 1; min-width: 0; }
    .ddp-head__name { font-family: var(--font-d); font-size: var(--t-xl); font-weight: 700; color: var(--ink); letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: var(--s1); }
    .ddp-head__meta { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; }
    .ddp-close { width: 32px; height: 32px; border-radius: 50%; border: 1.5px solid var(--border); background: var(--white); display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; transition: all var(--t-fast); }
    .ddp-close:hover { background: var(--off); }

    .ddp-body { padding: var(--s5) var(--s6); flex: 1; }
    .ddp-section { margin-bottom: var(--s6); }
    .ddp-section__title { font-size: var(--t-xs); font-weight: 700; text-transform: uppercase; letter-spacing: .1em; color: var(--text-m); margin-bottom: var(--s3); display: flex; align-items: center; gap: var(--s2); }

    .ddp-ai-box { background: linear-gradient(135deg, rgba(37,99,235,.04) 0%, rgba(124,58,237,.04) 100%); border: 1.5px solid rgba(37,99,235,.15); border-radius: var(--r-xl); padding: var(--s5); position: relative; overflow: hidden; }
    .ddp-ai-box::before { content: ''; position: absolute; top: -1px; left: 0; right: 0; height: 2px; background: linear-gradient(90deg, var(--blue), #7C3AED); }
    .ddp-ai-label { display: flex; align-items: center; gap: var(--s2); margin-bottom: var(--s3); }
    .ddp-ai-text { font-size: var(--t-sm); color: var(--text-s); line-height: 1.65; }
    .ddp-ai-tags { display: flex; gap: var(--s2); margin-top: var(--s3); flex-wrap: wrap; }
    .ddp-ai-tag { background: var(--blue-pale); border: 1px solid rgba(37,99,235,.2); color: var(--blue); font-size: 11px; font-weight: 600; padding: 3px 10px; border-radius: var(--r-pill); }

    .ddp-meta-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s4); }
    .ddp-meta-item__label { font-size: var(--t-xs); font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--text-m); margin-bottom: var(--s1); }
    .ddp-meta-item__val { font-size: var(--t-sm); font-weight: 700; color: var(--ink); }

    .ddp-preview-frame { background: var(--off); border: 1px solid var(--border); border-radius: var(--r-xl); min-height: 200px; display: flex; align-items: center; justify-content: center; position: relative; overflow: hidden; }
    .ddp-preview-frame img { max-width: 100%; max-height: 320px; object-fit: contain; border-radius: var(--r-lg); }
    .ddp-preview-placeholder { text-align: center; }
    .ddp-preview-placeholder__icon { font-size: 3rem; opacity: .3; margin-bottom: var(--s3); }
    .ddp-preview-placeholder__text { font-size: var(--t-sm); color: var(--text-m); }

    .ddp-actions { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); padding: var(--s5) var(--s6); border-top: 1px solid var(--border); }

    /* ── OCR FIELDS ── */
    .ocr-fields { display: flex; flex-direction: column; gap: var(--s3); }
    .ocr-field { display: flex; align-items: flex-start; gap: var(--s3); padding: var(--s3) var(--s4); background: var(--off); border: 1px solid var(--border); border-radius: var(--r-lg); }
    .ocr-field__key { font-size: var(--t-xs); font-weight: 700; color: var(--text-m); min-width: 100px; flex-shrink: 0; text-transform: uppercase; letter-spacing: .06em; line-height: 1.5; }
    .ocr-field__val { font-size: var(--t-sm); font-weight: 600; color: var(--ink); line-height: 1.4; word-break: break-word; }

    /* ── STATUS BADGE VARIANTS ── */
    .badge--verified { background: rgba(5,150,105,.1); color: var(--ok); }
    .badge--pending  { background: var(--amber-pale); color: var(--amber); }
    .badge--processing { background: var(--blue-pale); color: var(--blue); }
    .badge--rejected { background: rgba(239,68,68,.1); color: #DC2626; }

    /* ── HIDDEN/SHOW ── */
    .view-list .grid-view { display: none; }
    .view-grid .list-view { display: none; }

    /* ── RESPONSIVE ── */
    @media(max-width:1100px) {
      .docs-stats { grid-template-columns: repeat(2, 1fr); }
      .doc-detail-panel { width: 100%; }
    }
    @media(max-width:768px) {
      .db-page { padding: var(--s5) var(--s4); }
      .docs-stats { grid-template-columns: repeat(2, 1fr); }
      .docs-controls { flex-direction: column; align-items: stretch; }
      .docs-filter { overflow-x: auto; padding-bottom: var(--s1); }
      .docs-search { min-width: 100%; }
      .docs-table thead th:nth-child(4),
      .docs-table tbody td:nth-child(4),
      .docs-table thead th:nth-child(5),
      .docs-table tbody td:nth-child(5) { display: none; }
      .ddp-meta-grid { grid-template-columns: 1fr; }
    }
    @media(max-width:480px) {
      .docs-stats { grid-template-columns: 1fr 1fr; }
      .doc-type-select__grid { grid-template-columns: repeat(2, 1fr); }
      .docs-grid { grid-template-columns: 1fr; }
    }
