/* =====================================================
   MODULE: TABLES
   Glow frame + frosted row system from Print OS v4.
   Full per-theme overrides for all 5 themes.
   Toggle: modules.tables in theme-config.json
   ===================================================== */

/* ============= TABLE FRAME (Print OS glow border) ============= */
.table-frame {
    border: var(--ol-thick) solid var(--table-border);
    box-shadow: var(--table-glow);
    border-radius: var(--table-radius);
    overflow: hidden;
}

/* ============= ROW GLOW ============= */
.tr-glow {
    border-bottom: var(--ol-med) solid var(--table-row-border);
    box-shadow: var(--table-row-glow);
}

/* ============= BASE TABLE ============= */
.table-wrapper {
    overflow-x: auto;
    border-radius: var(--table-radius);
    border: 1px solid var(--table-border);
    box-shadow: var(--table-glow);
}

.table {
    width: 100%;
    border-collapse: collapse;
    background: var(--table-bg);
    font-size: var(--font-size-sm, 0.875rem);
}

.table th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-size: var(--font-size-xs, 0.75rem);
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-tertiary);
    background: var(--table-header-bg);
    border-bottom: 2px solid var(--table-border);
}

.table td {
    padding: 0.75rem 1rem;
    color: var(--text-primary);
    border-bottom: 1px solid var(--table-row-border);
}

.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--table-row-hover); }

/* ============= TABLE VARIANTS ============= */
.table-striped tr:nth-child(even) td { background: var(--bg-tertiary); }
.table-compact th, .table-compact td { padding: 0.5rem 0.75rem; font-size: var(--font-size-xs); }
.table-bordered th, .table-bordered td { border: 1px solid var(--table-border); }

/* ============= SORTABLE HEADERS ============= */
.table th.sortable { cursor: pointer; user-select: none; transition: color 0.2s ease; }
.table th.sortable:hover { color: var(--accent); }
.table th.sortable::after { content: ' \2195'; opacity: 0.4; font-size: 0.7em; }
.table th.sort-asc::after { content: ' \2191'; opacity: 1; color: var(--accent); }
.table th.sort-desc::after { content: ' \2193'; opacity: 1; color: var(--accent); }

/* ============= TABLE ACTIONS ============= */
.table .actions { display: flex; gap: 0.5rem; justify-content: flex-end; width: max-content; margin-left: auto; }
td.actions,
td.cell-actions {
    width: 1%;
    white-space: nowrap;
    padding-left: 0.5rem;
    padding-right: 0.625rem;
}

/* ============= STATUS CELLS ============= */
.table .cell-status,
.data-table .cell-status { display: inline-flex; align-items: center; gap: 0.375rem; }
.table .cell-status::before,
.data-table .cell-status::before {
    content: '';
    width: 0.5rem; height: 0.5rem;
    border-radius: 50%;
    background: var(--text-tertiary);
}
.table .cell-status.active::before,
.data-table .cell-status.active::before  { background: var(--color-success); }
.table .cell-status.pending::before,
.data-table .cell-status.pending::before { background: var(--color-warning); }
.table .cell-status.error::before,
.data-table .cell-status.error::before   { background: var(--color-danger); }

/* ============= PRICE TABLE ============= */
.price-table { width: 100%; border-collapse: collapse; font-size: var(--font-size-xs); }
.price-table th {
    padding: 0.5rem;
    background: var(--table-header-bg);
    font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
    color: var(--text-tertiary);
    border-bottom: 1px solid var(--table-border);
    text-align: center;
}
.price-table td {
    padding: 0.5rem; text-align: center;
    border-bottom: 1px solid var(--table-border);
    color: var(--text-primary);
}
.price-table .price-highlight { font-weight: 700; color: var(--accent); }

/* ============= SUMMARY CELLS ============= */
.summary-cell {
    border-radius: var(--radius-lg);
    padding: 0.75rem;
    text-align: center;
}
.summary-red {
    background: var(--summary-red-bg);
    border: 1px solid var(--summary-red-border);
    box-shadow: 0 0 15px var(--summary-red-border);
}
.summary-red .summary-label, .summary-red .summary-value { color: var(--summary-red-text); }

.summary-blue {
    background: var(--summary-blue-bg);
    border: 1px solid var(--summary-blue-border);
    box-shadow: 0 0 15px var(--summary-blue-border);
}
.summary-blue .summary-label, .summary-blue .summary-value { color: var(--summary-blue-text); }

.summary-green {
    background: var(--summary-green-bg);
    border: 1px solid var(--summary-green-border);
    box-shadow: 0 0 15px var(--summary-green-border);
}
.summary-green .summary-label, .summary-green .summary-value { color: var(--summary-green-text); }

/* ============= SPREADSHEET TABLE (Excel/Sheets style) ============= */
.spreadsheet {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-size-xs, 0.75rem);
    font-family: "SF Mono", "Fira Code", monospace;
}
.spreadsheet th,
.spreadsheet td {
    padding: 0.375rem 0.625rem;
    border: 1px solid var(--table-border);
    text-align: left;
    color: var(--text-primary);
    white-space: nowrap;
}
.spreadsheet thead th {
    background: var(--table-header-bg);
    color: var(--text-tertiary);
    font-weight: 600;
    text-align: center;
    position: sticky;
    top: 0;
    z-index: 2;
}
.spreadsheet .row-num {
    background: var(--table-header-bg);
    color: var(--text-tertiary);
    font-weight: 600;
    text-align: center;
    width: 2.5rem;
    min-width: 2.5rem;
    position: sticky;
    left: 0;
    z-index: 1;
}
.spreadsheet td.cell-selected {
    outline: 2px solid var(--accent);
    outline-offset: -1px;
    background: var(--bg-accent-subtle);
}
.spreadsheet td.cell-formula {
    color: var(--color-info);
    font-style: italic;
}
.spreadsheet td.cell-number {
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.spreadsheet-wrapper {
    overflow: auto;
    max-height: 300px;
    border: 1px solid var(--table-border);
    border-radius: var(--table-radius);
}

/* ============= DATABASE / INFO TABLE (people, jobs, assets) ============= */
.data-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    font-size: var(--font-size-sm, 0.875rem);
}
.data-table th {
    padding: 0.625rem 1rem;
    text-align: left;
    font-size: var(--font-size-xs, 0.75rem);
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-tertiary);
    background: var(--table-header-bg);
    border-bottom: 2px solid var(--table-border);
}
.data-table td {
    padding: 0.625rem 1rem;
    color: var(--text-primary);
    border-bottom: 1px solid var(--table-row-border);
    vertical-align: middle;
}
.data-table tr:hover td { background: var(--table-row-hover); }
.data-table tr:last-child td { border-bottom: none; }

/* Fixed layout: non-first columns get tight widths, first column absorbs the rest */
.data-table th:not(:first-child),
.data-table td:not(:first-child) { white-space: nowrap; width: 7rem; overflow: visible; }
.data-table td.cell-actions { width: 5rem; }

/* User/person row with avatar */
.data-table .cell-user {
    display: flex;
    align-items: center;
    gap: 0.625rem;
}
.data-table .cell-user-avatar {
    width: 2rem; height: 2rem;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    color: #fff;
    background: var(--accent);
    flex-shrink: 0;
}
.data-table .cell-user-info { display: flex; flex-direction: column; }
.data-table .cell-user-name { font-weight: 600; color: var(--text-primary); }
.data-table .cell-user-meta { font-size: var(--font-size-xs, 0.75rem); color: var(--text-tertiary); }

/* Role/status badges inside tables */
.data-table .cell-role {
    display: inline-flex;
    padding: 0.15rem 0.5rem;
    font-size: var(--font-size-xs, 0.75rem);
    font-weight: 600;
    border-radius: var(--radius-full, 9999px);
    background: var(--bg-accent-subtle);
    color: var(--accent);
    border: 1px solid var(--border-primary);
}
.data-table .cell-actions {
    display: flex;
    gap: 0.375rem;
    justify-content: flex-end;
    align-items: center;
    white-space: nowrap;
}
.data-table .cell-actions .btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    border-width: 1px;
    min-height: unset;
    line-height: 1.2;
}

/* ============= RESPONSIVE ============= */
@media (max-width: 640px) {
    .table-responsive thead { display: none; }
    .table-responsive tr {
        display: block; margin-bottom: 0.75rem;
        border: 1px solid var(--table-border);
        border-radius: var(--radius-md);
    }
    .table-responsive td {
        display: flex; justify-content: space-between; padding: 0.5rem 0.75rem;
    }
    .table-responsive td::before {
        content: attr(data-label); font-weight: 600; color: var(--text-tertiary);
    }
}

/* ============= BLACK GLASS THEME — frosted rows ============= */
[data-theme="black-glass"] .table,
[data-theme="black-glass"] .spreadsheet,
[data-theme="black-glass"] .data-table { border-color: rgba(255, 255, 255, 0.06); }
[data-theme="black-glass"] th { background: rgba(0, 0, 0, 0.35); border-color: rgba(255, 255, 255, 0.06) !important; }
[data-theme="black-glass"] td { background: rgba(0, 0, 0, 0.2); border-color: rgba(255, 255, 255, 0.04) !important; }
[data-theme="black-glass"] .table-frame { border-color: rgba(255, 255, 255, 0.06); }
[data-theme="black-glass"] .spreadsheet-wrapper { border-color: rgba(255, 255, 255, 0.06); }
[data-theme="black-glass"] tr:hover td { background: rgba(255, 255, 255, 0.04); }

/* ============= LIGHT THEME — slight transparency ============= */
[data-theme="white-glass"] .table,
[data-theme="white-glass"] .spreadsheet,
[data-theme="white-glass"] .data-table { border-color: rgba(0, 0, 0, 0.1); }
[data-theme="white-glass"] th { background: rgba(241, 245, 249, 0.85); color: #334155; border-color: rgba(0, 0, 0, 0.1) !important; }
[data-theme="white-glass"] td { background: rgba(255, 255, 255, 0.8); color: #1e293b; border-color: rgba(0, 0, 0, 0.06) !important; }
[data-theme="white-glass"] tr:hover td { background: rgba(248, 250, 252, 0.9); }
[data-theme="white-glass"] .table-frame {
    border: 1px solid rgba(0, 0, 0, 0.1);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    background: rgba(255, 255, 255, 0.94);
}
[data-theme="white-glass"] .tr-glow {
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    box-shadow: none;
}
[data-theme="white-glass"] .summary-cell { border: none; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12); }
[data-theme="white-glass"] .summary-cell, [data-theme="white-glass"] .summary-cell * { color: white; }
[data-theme="white-glass"] .summary-red   { background: var(--accent); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12); }
[data-theme="white-glass"] .summary-blue  { background: #2563eb; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12); }
[data-theme="white-glass"] .summary-green { background: #16a34a; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12); }
/* White glass spreadsheet + data table */
[data-theme="white-glass"] .spreadsheet th { background: rgba(241, 245, 249, 0.85); color: #334155; }
[data-theme="white-glass"] .spreadsheet td { background: rgba(255, 255, 255, 0.8); border-color: rgba(0,0,0,0.08); color: #1e293b; }
[data-theme="white-glass"] .spreadsheet .row-num { background: rgba(241, 245, 249, 0.85); color: #334155; }
[data-theme="white-glass"] .spreadsheet td.cell-selected { background: rgba(237, 233, 254, 0.85); outline-color: var(--accent); }
[data-theme="white-glass"] .spreadsheet-wrapper { border-color: rgba(0,0,0,0.1); }
[data-theme="white-glass"] .data-table th { background: rgba(241, 245, 249, 0.85); color: #334155; }
[data-theme="white-glass"] .data-table td { background: rgba(255, 255, 255, 0.8); color: #1e293b; }
[data-theme="white-glass"] .data-table .cell-user-avatar { background: var(--accent); }
[data-theme="white-glass"] .data-table .cell-role { background: rgba(241, 245, 249, 0.85); color: var(--accent); border-color: rgba(0,0,0,0.08); }
[data-theme="white-glass"] .data-table .cell-status.active::before { background: #16a34a; }
[data-theme="white-glass"] .data-table .cell-status.pending::before { background: #f59e0b; }

/* ============= RETRO THEME — sunken 3D ============= */
[data-theme="retro"] .table-frame {
    border: none; border-radius: 0;
    box-shadow: inset -1px -1px #ffffff, inset 1px 1px #808080, inset -2px -2px #dfdfdf, inset 2px 2px #0a0a0a;
}
[data-theme="retro"] .tr-glow { border-bottom: 1px solid #808080; box-shadow: none; }
[data-theme="retro"] th { background: #c0c0c0 !important; color: #000; font-weight: 700; }
[data-theme="retro"] td { background: #fff !important; color: #000; }
[data-theme="retro"] .table-wrapper { border-radius: 0; }
[data-theme="retro"] .summary-cell { border-radius: 0; box-shadow: inset -1px -1px 0 #808080, inset 1px 1px 0 #fff; }
[data-theme="retro"] .summary-red { background: #800000; border: 2px solid #808080; }
[data-theme="retro"] .summary-red .summary-label, [data-theme="retro"] .summary-red .summary-value { color: #fff; }
[data-theme="retro"] .summary-blue { background: #000080; border: 2px solid #808080; }
[data-theme="retro"] .summary-blue .summary-label, [data-theme="retro"] .summary-blue .summary-value { color: #fff; }
[data-theme="retro"] .summary-green { background: #008000; border: 2px solid #808080; }
[data-theme="retro"] .summary-green .summary-label, [data-theme="retro"] .summary-green .summary-value { color: #fff; }

/* Retro spreadsheet */
[data-theme="retro"] .spreadsheet { font-family: "Courier New", monospace; }
[data-theme="retro"] .spreadsheet th,
[data-theme="retro"] .spreadsheet td { border-color: #808080; }
[data-theme="retro"] .spreadsheet thead th { background: #c0c0c0; color: #000; }
[data-theme="retro"] .spreadsheet .row-num { background: #c0c0c0; color: #000; }
[data-theme="retro"] .spreadsheet td { background: #fff; color: #000; }
[data-theme="retro"] .spreadsheet td.cell-selected {
    outline-color: #000080;
    background: #000080;
    color: #fff;
}
[data-theme="retro"] .spreadsheet-wrapper { border-radius: 0; }
[data-theme="retro"] .data-table .cell-user-avatar { border-radius: 0; background: #000080; }
[data-theme="retro"] .data-table .cell-role { border-radius: 0; background: #c0c0c0; border-color: #808080; color: #000; }

/* ============= HOMEBREW THEME — green lines ============= */
[data-theme="homebrew"] .table-frame {
    border: 1px solid rgba(0, 255, 0, 0.2);
    box-shadow: 0 0 6px rgba(0, 255, 0, 0.05);
    border-radius: 0;
}
[data-theme="homebrew"] .tr-glow { border-bottom: 1px solid rgba(0, 255, 0, 0.1); box-shadow: none; }
[data-theme="homebrew"] th { background: rgba(0, 255, 0, 0.04) !important; color: #00ff00; }
[data-theme="homebrew"] td { background: rgba(0, 0, 0, 0.3) !important; color: #00ff00; }
[data-theme="homebrew"] .table-wrapper { border-radius: 0; }
/* Homebrew spreadsheet */
[data-theme="homebrew"] .spreadsheet { font-family: "Courier New", monospace; }
[data-theme="homebrew"] .spreadsheet th,
[data-theme="homebrew"] .spreadsheet td { border-color: rgba(0,255,0,0.15); color: #00ff00; }
[data-theme="homebrew"] .spreadsheet thead th { background: rgba(0,255,0,0.04); color: #00cc00; }
[data-theme="homebrew"] .spreadsheet .row-num { background: rgba(0,255,0,0.04); color: #008800; }
[data-theme="homebrew"] .spreadsheet td { background: rgba(0,0,0,0.3); }
[data-theme="homebrew"] .spreadsheet td.cell-selected {
    outline-color: #00ff00;
    background: rgba(0,255,0,0.08);
}
[data-theme="homebrew"] .spreadsheet td.cell-number { color: #00ff00; }
[data-theme="homebrew"] .spreadsheet-wrapper { border-radius: 0; border-color: rgba(0,255,0,0.2); }
[data-theme="homebrew"] .data-table .cell-user-avatar { border-radius: 0; background: rgba(0,255,0,0.2); color: #00ff00; }
[data-theme="homebrew"] .data-table .cell-role { border-radius: 0; background: rgba(0,255,0,0.06); border-color: rgba(0,255,0,0.2); color: #00ff00; }

/* ============= SKEUOMORPHIC THEME — raised tables ============= */
[data-theme="skeuomorphic"] .table {
    box-shadow: 0 2px 8px rgba(0,0,0,0.08), inset 0 1px 0 rgba(255,255,255,0.6);
    border: 1px solid rgba(0,0,0,0.08);
}
[data-theme="skeuomorphic"] .table thead th {
    background: linear-gradient(to bottom, #f0ebe3, #e3ddd4);
    border-bottom: 1px solid rgba(0,0,0,0.1);
    text-shadow: 0 1px 0 rgba(255,255,255,0.5);
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.5);
}
[data-theme="skeuomorphic"] .table-striped tbody tr:nth-child(even) {
    background: #f5f0e8;
}
[data-theme="skeuomorphic"] .table tbody tr:hover {
    background: #eee9e0;
}
