/* ============================================================
   Server Admin - Disk Usage Visualizer
   ============================================================ */

/* -- CSS Custom Properties (Light Theme) -- */
:root {
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    --border-hover: #cbd5e1;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --danger: #ef4444;
    --success: #22c55e;
    --warning: #f59e0b;
    --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    --card-shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.1);
    --progress-bg: #e2e8f0;
    --progress-bar: #2563eb;
    --progress-warn: #f59e0b;
    --progress-danger: #ef4444;
    --treemap-border: rgba(255, 255, 255, 0.6);
    --tooltip-bg: #1e293b;
    --tooltip-text: #f1f5f9;
    --table-stripe: #f8fafc;
    --table-hover: #eff6ff;
    --breadcrumb-bg: #f1f5f9;
    --spinner-color: #2563eb;
}

/* -- Dark Theme -- */
[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border-color: #334155;
    --border-hover: #475569;
    --accent: #3b82f6;
    --accent-hover: #60a5fa;
    --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    --card-shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.3);
    --progress-bg: #334155;
    --treemap-border: rgba(0, 0, 0, 0.4);
    --tooltip-bg: #334155;
    --tooltip-text: #e2e8f0;
    --table-stripe: #1e293b;
    --table-hover: rgba(59, 130, 246, 0.1);
    --breadcrumb-bg: #1e293b;
}

/* -- Base -- */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

/* -- Content Wrapper -- */
.content-wrapper {
    max-width: 1800px;
    margin: 0 auto;
    padding: 20px;
}

/* -- Disk Overview Cards -- */
.disk-overview {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.disk-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 14px 16px;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
    box-shadow: var(--card-shadow);
}

.disk-card:hover {
    border-color: var(--accent);
    box-shadow: var(--card-shadow-hover);
}

.disk-card.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

.disk-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.disk-card-mount {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.disk-card-device {
    font-size: 11px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.disk-card-stats {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.disk-progress {
    width: 100%;
    height: 6px;
    background: var(--progress-bg);
    border-radius: 3px;
    overflow: hidden;
}

.disk-progress-bar {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s ease;
    background: var(--progress-bar);
}

.disk-progress-bar.warn { background: var(--progress-warn); }
.disk-progress-bar.danger { background: var(--progress-danger); }

.disk-card-percent {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
}

/* -- Breadcrumb Navigation -- */
.breadcrumb-bar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
    background: var(--breadcrumb-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-bottom: 16px;
    overflow-x: auto;
    white-space: nowrap;
    font-size: 13px;
}

.breadcrumb-item {
    color: var(--accent);
    cursor: pointer;
    text-decoration: none;
    padding: 2px 4px;
    border-radius: 4px;
    transition: background 0.15s;
    flex-shrink: 0;
}

.breadcrumb-item:hover {
    background: rgba(37, 99, 235, 0.1);
}

.breadcrumb-item.current {
    color: var(--text-primary);
    font-weight: 600;
    cursor: default;
}

.breadcrumb-item.current:hover {
    background: none;
}

.breadcrumb-sep {
    color: var(--text-muted);
    flex-shrink: 0;
    font-size: 11px;
}

.breadcrumb-info {
    margin-left: auto;
    color: var(--text-muted);
    font-size: 12px;
    flex-shrink: 0;
}

/* -- Main Content Grid -- */
.main-content {
    display: grid;
    grid-template-columns: 1fr 400px;
    gap: 16px;
    margin-bottom: 16px;
}

/* -- Treemap Container -- */
.treemap-container {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    min-height: 450px;
    position: relative;
    overflow: hidden;
    box-shadow: var(--card-shadow);
}

.treemap-container svg {
    display: block;
    width: 100%;
    height: 100%;
}

.treemap-container svg rect {
    stroke: var(--treemap-border);
    stroke-width: 1px;
    cursor: pointer;
    transition: opacity 0.15s;
}

.treemap-container svg rect:hover {
    opacity: 0.85;
}

.treemap-container svg text {
    pointer-events: none;
    fill: #fff;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.treemap-label-name {
    font-weight: 600;
    font-size: 12px;
}

.treemap-label-size {
    font-size: 10px;
    opacity: 0.85;
}

/* -- Directory Table -- */
.table-container {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--card-shadow);
    display: flex;
    flex-direction: column;
    max-height: 600px;
}

.table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-tertiary);
}

.table-header h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.table-count {
    font-size: 12px;
    color: var(--text-muted);
}

.table-scroll {
    overflow-y: auto;
    flex: 1;
}

.dir-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.dir-table thead th {
    position: sticky;
    top: 0;
    background: var(--bg-tertiary);
    padding: 8px 12px;
    text-align: left;
    font-weight: 600;
    font-size: 12px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
}

.dir-table thead th:hover {
    color: var(--accent);
}

.dir-table thead th.sort-active {
    color: var(--accent);
}

.dir-table thead th .sort-icon {
    margin-left: 4px;
    font-size: 10px;
    opacity: 0.5;
}

.dir-table thead th.sort-active .sort-icon {
    opacity: 1;
}

.dir-table tbody tr {
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.1s;
}

.dir-table tbody tr:nth-child(even) {
    background: var(--table-stripe);
}

.dir-table tbody tr:hover {
    background: var(--table-hover);
}

.dir-table tbody tr.selected {
    background: rgba(37, 99, 235, 0.1);
}

.dir-table td {
    padding: 7px 12px;
    vertical-align: middle;
}

.dir-table .cell-name {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.dir-table .cell-name span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dir-table .cell-icon {
    font-size: 14px;
    flex-shrink: 0;
    width: 18px;
    text-align: center;
}

.dir-table .cell-size {
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    color: var(--text-secondary);
}

.dir-table .cell-percent {
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
    font-size: 12px;
}

.dir-table .cell-bar {
    width: 60px;
}

.cell-mini-bar {
    width: 100%;
    height: 4px;
    background: var(--progress-bg);
    border-radius: 2px;
    overflow: hidden;
}

.cell-mini-bar-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.3s;
}

/* -- File Type Legend -- */
.legend-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 12px;
    box-shadow: var(--card-shadow);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
    color: var(--text-secondary);
}

.legend-swatch {
    width: 12px;
    height: 12px;
    border-radius: 2px;
    flex-shrink: 0;
}

/* -- Tooltip -- */
.treemap-tooltip {
    position: fixed;
    padding: 8px 12px;
    background: var(--tooltip-bg);
    color: var(--tooltip-text);
    border-radius: 6px;
    font-size: 12px;
    pointer-events: none;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    max-width: 300px;
    display: none;
    line-height: 1.4;
}

.treemap-tooltip .tt-name {
    font-weight: 600;
    margin-bottom: 2px;
    word-break: break-all;
}

.treemap-tooltip .tt-size {
    color: var(--accent);
    font-variant-numeric: tabular-nums;
}

.treemap-tooltip .tt-percent {
    opacity: 0.7;
}

.treemap-tooltip .tt-type {
    opacity: 0.6;
    font-size: 11px;
    margin-top: 2px;
}

/* -- Loading Spinner -- */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.8);
    z-index: 10;
    gap: 12px;
}

[data-theme="dark"] .loading-overlay {
    background: rgba(15, 23, 42, 0.8);
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border-color);
    border-top-color: var(--spinner-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-text {
    font-size: 13px;
    color: var(--text-muted);
}

/* -- Toast Notifications -- */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 10px 16px;
    border-radius: 6px;
    font-size: 13px;
    color: white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    animation: toastIn 0.3s ease;
    max-width: 350px;
}

.toast.error { background: var(--danger); }
.toast.info { background: var(--accent); }

@keyframes toastIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* -- Info Panel -- */
.info-panel {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 12px;
    color: var(--text-muted);
    box-shadow: var(--card-shadow);
}

.info-panel .scan-time {
    color: var(--text-secondary);
}

.info-panel .cache-badge {
    display: inline-block;
    padding: 1px 6px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 3px;
    font-size: 11px;
}

.info-panel-buttons {
    margin-left: auto;
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.info-panel .refresh-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 12px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
}

.info-panel .refresh-btn:hover {
    background: var(--accent-hover);
}

.info-panel .refresh-btn svg {
    flex-shrink: 0;
}

.info-panel .rescan-server-btn {
    background: #64748b;
}

.info-panel .rescan-server-btn:hover {
    background: #475569;
}

/* -- Confirmation Overlay -- */
.confirm-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    justify-content: center;
    align-items: center;
}

.confirm-overlay.active {
    display: flex;
}

.confirm-box {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 24px;
    max-width: 420px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    text-align: center;
}

.confirm-box h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 10px;
}

.confirm-box p {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 20px;
}

.confirm-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.btn-confirm-cancel,
.btn-confirm-ok {
    padding: 8px 20px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-confirm-cancel {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-confirm-cancel:hover {
    background: var(--border-color);
}

.btn-confirm-ok {
    background: var(--accent);
    color: white;
}

.btn-confirm-ok:hover {
    background: var(--accent-hover);
}

/* -- Responsive -- */
@media (max-width: 900px) {
    .main-content {
        grid-template-columns: 1fr;
    }

    .content-wrapper {
        padding: 12px;
    }

    .disk-overview {
        grid-template-columns: 1fr 1fr;
    }

    .table-container {
        max-height: 400px;
    }
}

@media (max-width: 600px) {
    .disk-overview {
        grid-template-columns: 1fr;
    }

    .breadcrumb-info {
        display: none;
    }

    .legend-bar {
        gap: 6px;
    }

    .legend-item {
        font-size: 11px;
    }
}
