/* ============================================================================
   IG Document Archive & File Management System (IG-DAMS) - Admin Panel
   Brand Colors: Orange #E8792B, Navy #1B2A4A
   ============================================================================ */

:root {
    --orange: #E8792B;
    --orange-hover: #d06a22;
    --orange-light: rgba(232, 121, 43, 0.08);
    --orange-glow: rgba(232, 121, 43, 0.15);
    --navy: #1B2A4A;
    --navy-light: #253a5e;
    --navy-dark: #111d33;
    --bg: #f4f6f9;
    --white: #ffffff;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --green: #10b981;
    --green-light: #d1fae5;
    --red: #ef4444;
    --red-light: #fef2f2;
    --yellow: #f59e0b;
    --blue: #3b82f6;
    --blue-light: #dbeafe;
    --sidebar-width: 250px;
    --topbar-height: 56px;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.1);
    --transition: 0.2s ease;
}

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

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

/* ===== Loading & Access Denied Screens ===== */
#loading-screen, #access-denied {
    position: fixed; inset: 0;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    background: linear-gradient(135deg, var(--navy) 0%, var(--navy-dark) 100%);
    color: white; z-index: 9999;
}
#loading-screen .spinner {
    width: 48px; height: 48px;
    border: 4px solid rgba(255,255,255,0.2);
    border-top-color: var(--orange);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 16px;
}
#loading-screen p { color: var(--gray-400); font-size: 14px; }
@keyframes spin { to { transform: rotate(360deg); } }

#access-denied { display: none; }
#access-denied h2 { font-size: 24px; margin-bottom: 8px; }
#access-denied p { color: var(--gray-400); margin-bottom: 24px; font-size: 14px; }

/* ===== Login Screen ===== */
#login-screen {
    display: none;
    position: fixed; inset: 0;
    background: linear-gradient(135deg, var(--navy) 0%, var(--navy-dark) 100%);
    z-index: 9998;
    align-items: center; justify-content: center;
}
#login-screen.visible { display: flex; }

.login-container {
    width: 100%; max-width: 420px; padding: 20px;
}
.login-brand {
    text-align: center; margin-bottom: 32px;
}
.login-brand h1 {
    color: var(--orange); font-size: 24px; font-weight: 700; margin-bottom: 4px;
}
.login-brand p { color: var(--gray-400); font-size: 14px; }
.login-card {
    background: var(--white); border-radius: var(--radius-lg);
    padding: 32px; box-shadow: var(--shadow-lg);
}
.login-card h2 {
    color: var(--navy); font-size: 20px; margin-bottom: 4px;
}
.login-card .subtitle {
    color: var(--gray-500); font-size: 14px; margin-bottom: 24px;
}
.login-tagline {
    text-align: center; margin-top: 24px;
    font-size: 13px; color: var(--gray-400); font-style: italic;
}
.email-sent-state { display: none; text-align: center; }
.email-sent-state.visible { display: block; }
.email-sent-icon {
    width: 64px; height: 64px; margin: 0 auto 16px;
    background: var(--orange-light); border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 28px;
}

/* ===== App Layout ===== */
#app { display: none; }

.sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    width: var(--sidebar-width);
    background: var(--navy);
    color: white;
    display: flex; flex-direction: column;
    z-index: 100;
    transition: width var(--transition);
}
.sidebar-header {
    padding: 18px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-header h1 {
    font-size: 16px; font-weight: 700; color: var(--orange);
}
.sidebar-header p {
    font-size: 11px; color: var(--gray-400); margin-top: 2px;
}
.sidebar-nav {
    flex: 1; padding: 8px 0; overflow-y: auto;
}
.sidebar-nav .section-label {
    font-size: 10px; text-transform: uppercase; letter-spacing: 1.2px;
    color: var(--gray-500); padding: 18px 20px 6px; font-weight: 600;
}
.sidebar-nav a {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 20px; color: var(--gray-300);
    text-decoration: none; font-size: 13px;
    transition: all 0.15s;
    border-left: 3px solid transparent;
}
.sidebar-nav a:hover {
    background: rgba(255,255,255,0.06); color: white;
}
.sidebar-nav a.active {
    background: rgba(232,121,43,0.12); color: var(--orange);
    border-left-color: var(--orange); font-weight: 600;
}
.sidebar-nav a .icon {
    font-size: 16px; width: 22px; text-align: center; flex-shrink: 0;
}
.sidebar-footer {
    padding: 14px 20px;
    border-top: 1px solid rgba(255,255,255,0.08);
    font-size: 12px; color: var(--gray-500);
}
.sidebar-footer .user-email {
    color: var(--gray-300); font-size: 13px; margin-bottom: 4px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-footer .user-role {
    display: inline-block; padding: 2px 8px; border-radius: 10px;
    font-size: 10px; font-weight: 600; text-transform: uppercase;
    background: rgba(232,121,43,0.2); color: var(--orange);
}
.sidebar-logout {
    display: block; width: 100%; margin-top: 8px;
    padding: 6px 0; background: none; border: none;
    color: var(--gray-400); font-size: 12px; cursor: pointer;
    text-align: left; transition: color 0.15s;
    font-family: inherit;
}
.sidebar-logout:hover { color: var(--red); }

.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh; padding: 24px;
    transition: margin-left var(--transition);
}

/* ===== Top Bar ===== */
.topbar {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 24px;
}
.topbar h2 { font-size: 22px; font-weight: 700; color: var(--navy); }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

/* ===== Cards ===== */
.card {
    background: white; border-radius: var(--radius-lg); padding: 20px;
    box-shadow: var(--shadow); border: 1px solid var(--gray-200);
    margin-bottom: 20px;
}
.card-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 16px;
}
.card-header h3 { font-size: 15px; font-weight: 600; color: var(--navy); }

/* ===== Metric Cards ===== */
.metric-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px; margin-bottom: 24px;
}
.metric-card {
    background: white; border-radius: var(--radius-lg); padding: 20px;
    box-shadow: var(--shadow); border: 1px solid var(--gray-200);
    position: relative; overflow: hidden;
}
.metric-card .metric-icon {
    font-size: 20px; margin-bottom: 8px;
}
.metric-card .metric-value {
    font-size: 28px; font-weight: 700; color: var(--navy);
}
.metric-card .metric-label {
    font-size: 12px; color: var(--gray-500); margin-top: 2px;
    text-transform: uppercase; letter-spacing: 0.5px;
}
.metric-card.highlight {
    border-left: 4px solid var(--orange);
}
.metric-card::after {
    content: ''; position: absolute; top: 0; right: 0;
    width: 60px; height: 60px;
    background: var(--orange-light); border-radius: 0 0 0 60px;
    opacity: 0.5;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 16px; border-radius: 6px; font-size: 13px;
    font-weight: 500; cursor: pointer; border: none;
    transition: all 0.15s; text-decoration: none;
    font-family: inherit; line-height: 1.4;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--orange); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--orange-hover); box-shadow: var(--shadow-md); }
.btn-secondary {
    background: var(--white); color: var(--gray-700);
    border: 1px solid var(--gray-300);
}
.btn-secondary:hover:not(:disabled) { background: var(--gray-50); border-color: var(--gray-400); }
.btn-danger { background: var(--red); color: white; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }
.btn-success { background: var(--green); color: white; }
.btn-success:hover:not(:disabled) { background: #059669; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 12px 28px; font-size: 15px; font-weight: 600; }
.btn-block { width: 100%; justify-content: center; }
.btn-icon {
    width: 32px; height: 32px; padding: 0;
    justify-content: center; border-radius: 6px;
}

/* ===== Forms ===== */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block; font-size: 13px; font-weight: 600;
    color: var(--gray-700); margin-bottom: 4px;
}
.form-group label .required { color: var(--orange); }
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%; padding: 9px 12px;
    border: 1px solid var(--gray-300); border-radius: 6px;
    font-size: 14px; font-family: inherit;
    outline: none; transition: border 0.15s, box-shadow 0.15s;
    background: var(--white); color: var(--gray-800);
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--orange);
    box-shadow: 0 0 0 3px var(--orange-glow);
}
.form-group input:disabled,
.form-group select:disabled {
    background: var(--gray-100); color: var(--gray-500); cursor: not-allowed;
}
.form-group textarea { resize: vertical; min-height: 80px; }
.form-hint { font-size: 12px; color: var(--gray-400); margin-top: 4px; }

/* ===== Tables ===== */
.table-container { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
    background: var(--gray-50); padding: 10px 12px; text-align: left;
    font-weight: 600; color: var(--gray-600);
    border-bottom: 2px solid var(--gray-200);
    white-space: nowrap; user-select: none;
}
thead th.sortable { cursor: pointer; }
thead th.sortable:hover { color: var(--navy); }
thead th .sort-arrow { font-size: 10px; margin-left: 4px; }
tbody td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--gray-100);
    vertical-align: middle;
}
tbody tr:hover { background: var(--gray-50); }
tbody tr.selected { background: var(--orange-light); }

/* ===== Badges ===== */
.badge {
    display: inline-block; padding: 2px 8px; border-radius: 10px;
    font-size: 11px; font-weight: 600; text-transform: uppercase;
}
.badge-viewer { background: var(--gray-100); color: var(--gray-600); }
.badge-editor { background: var(--blue-light); color: #1e40af; }
.badge-company_admin { background: #fef3c7; color: #92400e; }
.badge-super_admin { background: #fce7f3; color: #9d174d; }
.badge-active { background: var(--green-light); color: #065f46; }
.badge-inactive { background: var(--gray-200); color: var(--gray-600); }
.badge-suspended { background: var(--red-light); color: #991b1b; }
.badge-synced { background: var(--green-light); color: #065f46; }
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-conflict { background: var(--red-light); color: #991b1b; }

/* ===== Tabs ===== */
.tabs {
    display: flex; gap: 0;
    border-bottom: 2px solid var(--gray-200);
    margin-bottom: 20px;
}
.tab-btn {
    padding: 10px 20px; font-size: 13px; font-weight: 600;
    cursor: pointer; border: none; background: none;
    color: var(--gray-500); font-family: inherit;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px; transition: all 0.15s;
}
.tab-btn:hover { color: var(--navy); }
.tab-btn.active { color: var(--orange); border-bottom-color: var(--orange); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ===== Filters ===== */
.filters {
    display: flex; gap: 12px; margin-bottom: 16px;
    flex-wrap: wrap; align-items: center;
}
.filters select,
.filters input[type="text"],
.filters input[type="email"],
.filters input[type="date"] {
    padding: 7px 12px; border: 1px solid var(--gray-300);
    border-radius: 6px; font-size: 13px; outline: none;
    font-family: inherit;
    transition: border 0.15s;
}
.filters select:focus,
.filters input:focus {
    border-color: var(--orange);
}

/* ===== Pagination ===== */
.pagination {
    display: flex; gap: 4px; align-items: center;
    justify-content: center; margin-top: 16px;
}
.pagination button {
    padding: 6px 12px; border: 1px solid var(--gray-300);
    border-radius: 6px; background: var(--white); cursor: pointer;
    font-size: 13px; font-family: inherit;
    transition: all 0.15s;
}
.pagination button:hover { border-color: var(--orange); color: var(--orange); }
.pagination button.active {
    background: var(--orange); color: white; border-color: var(--orange);
}
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }
.pagination .page-info { font-size: 13px; color: var(--gray-500); margin: 0 8px; }

/* ===== Activity Feed ===== */
.activity-item {
    display: flex; gap: 12px; padding: 10px 0;
    border-bottom: 1px solid var(--gray-100);
}
.activity-item:last-child { border-bottom: none; }
.activity-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--orange); margin-top: 6px; flex-shrink: 0;
}
.activity-text { font-size: 13px; color: var(--gray-700); }
.activity-time { font-size: 11px; color: var(--gray-400); margin-top: 2px; }

/* ===== Drag & Drop Upload ===== */
.upload-zone {
    border: 2px dashed var(--gray-300);
    border-radius: var(--radius-lg);
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    background: var(--gray-50);
}
.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--orange);
    background: var(--orange-light);
}
.upload-zone .upload-icon { font-size: 36px; margin-bottom: 8px; }
.upload-zone .upload-text {
    font-size: 14px; color: var(--gray-500); margin-bottom: 4px;
}
.upload-zone .upload-text strong { color: var(--orange); }
.upload-zone .upload-hint {
    font-size: 12px; color: var(--gray-400);
}

.file-list { margin-top: 16px; }
.file-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 14px; background: var(--white);
    border: 1px solid var(--gray-200); border-radius: var(--radius);
    margin-bottom: 8px; transition: all 0.15s;
}
.file-item:hover { border-color: var(--gray-300); }
.file-type-icon {
    width: 36px; height: 36px; border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700; flex-shrink: 0;
}
.file-type-pdf { background: #fef2f2; color: #dc2626; }
.file-type-docx { background: #dbeafe; color: #1e40af; }
.file-type-xlsx { background: var(--green-light); color: #065f46; }
.file-type-txt { background: var(--gray-100); color: var(--gray-600); }
.file-type-csv { background: #fef3c7; color: #92400e; }
.file-type-img { background: #ede9fe; color: #6d28d9; }
.file-type-default { background: var(--gray-100); color: var(--gray-600); }

.file-info { flex: 1; min-width: 0; }
.file-name {
    font-size: 13px; font-weight: 600; color: var(--gray-800);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.file-size { font-size: 12px; color: var(--gray-400); }
.file-remove {
    background: none; border: none; color: var(--gray-400);
    cursor: pointer; font-size: 18px; padding: 4px;
    transition: color 0.15s;
}
.file-remove:hover { color: var(--red); }

.progress-bar-container {
    width: 100%; height: 6px; background: var(--gray-200);
    border-radius: 3px; overflow: hidden; margin-top: 6px;
}
.progress-bar {
    height: 100%; background: var(--orange); border-radius: 3px;
    transition: width 0.3s ease; width: 0%;
}

/* ===== Search Results ===== */
.search-result-card {
    background: var(--white); border: 1px solid var(--gray-200);
    border-radius: var(--radius); padding: 16px;
    margin-bottom: 12px; transition: all 0.15s;
    cursor: pointer;
}
.search-result-card:hover {
    border-color: var(--orange); box-shadow: var(--shadow-md);
}
.search-result-card .result-title {
    font-size: 15px; font-weight: 600; color: var(--navy); margin-bottom: 4px;
}
.search-result-card .result-meta {
    font-size: 12px; color: var(--gray-500); margin-bottom: 8px;
    display: flex; gap: 16px; flex-wrap: wrap;
}
.search-result-card .result-snippet {
    font-size: 13px; color: var(--gray-600); line-height: 1.5;
}
.search-result-card .result-snippet mark {
    background: #fef3c7; color: var(--gray-800);
    padding: 1px 2px; border-radius: 2px;
}
.search-result-card .result-tags {
    display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px;
}
.tag {
    display: inline-block; padding: 2px 8px; border-radius: 12px;
    font-size: 11px; background: var(--orange-light); color: var(--orange);
    font-weight: 500;
}

/* ===== Google Drive Panel ===== */
.split-panel {
    display: grid; grid-template-columns: 300px 1fr; gap: 20px;
    min-height: 500px;
}
.tree-panel {
    background: var(--white); border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg); padding: 16px;
    overflow-y: auto; max-height: 600px;
}
.tree-item {
    display: flex; align-items: center; gap: 6px;
    padding: 6px 8px; cursor: pointer; border-radius: 4px;
    font-size: 13px; color: var(--gray-700);
    transition: background 0.1s;
}
.tree-item:hover { background: var(--gray-50); }
.tree-item.active { background: var(--orange-light); color: var(--orange); font-weight: 600; }
.tree-item .tree-icon { font-size: 14px; flex-shrink: 0; }
.tree-item .tree-expand {
    width: 16px; text-align: center; font-size: 10px;
    cursor: pointer; color: var(--gray-400);
}
.tree-children { padding-left: 20px; }
.tree-children.collapsed { display: none; }

.sync-status {
    display: flex; align-items: center; gap: 6px;
    font-size: 12px; color: var(--gray-500);
    padding: 8px 12px; background: var(--gray-50);
    border-radius: 6px; margin-bottom: 12px;
}
.sync-dot {
    width: 8px; height: 8px; border-radius: 50%;
}
.sync-dot.synced { background: var(--green); }
.sync-dot.pending { background: var(--yellow); }
.sync-dot.error { background: var(--red); }

/* ===== Modal ===== */
.modal-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.5); z-index: 1000;
    align-items: center; justify-content: center;
    padding: 20px;
}
.modal-overlay.show { display: flex; animation: fadeIn 0.2s ease; }
.modal {
    background: white; border-radius: var(--radius-lg); padding: 24px;
    width: 90%; max-width: 540px; max-height: 90vh; overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal h3 {
    font-size: 18px; color: var(--navy); margin-bottom: 16px;
}
.modal-actions {
    display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px;
}

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

/* ===== Toast Notification ===== */
.toast {
    position: fixed; top: 20px; right: 20px;
    padding: 12px 20px; border-radius: var(--radius);
    font-size: 14px; color: white; z-index: 2000;
    transform: translateX(120%);
    transition: transform 0.3s ease;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    max-width: 400px;
}
.toast.show { transform: translateX(0); }
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }
.toast.info { background: var(--blue); }

/* ===== Checkbox ===== */
.checkbox-cell { width: 40px; text-align: center; }
.checkbox-cell input[type="checkbox"] {
    width: 16px; height: 16px; cursor: pointer;
    accent-color: var(--orange);
}

/* ===== Bulk Actions ===== */
.bulk-bar {
    display: none; align-items: center; gap: 12px;
    padding: 10px 16px; background: var(--navy);
    border-radius: var(--radius); margin-bottom: 12px;
    color: white; font-size: 13px;
}
.bulk-bar.visible { display: flex; }
.bulk-bar .bulk-count { font-weight: 600; }
.bulk-bar .btn { font-size: 12px; }

/* ===== Hidden Utility ===== */
.hidden { display: none !important; }
.page { display: none; }
.page.active { display: block; animation: fadeIn 0.25s ease; }

/* ===== Skeleton Loading ===== */
.skeleton {
    background: linear-gradient(90deg, var(--gray-200) 25%, var(--gray-100) 50%, var(--gray-200) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 4px;
}
.skeleton-line { height: 14px; margin-bottom: 8px; }
.skeleton-line.short { width: 60%; }
.skeleton-card { height: 80px; margin-bottom: 12px; border-radius: var(--radius); }
@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ===== Detail Grid ===== */
.detail-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}
.detail-item label {
    font-size: 11px; color: var(--gray-500); text-transform: uppercase;
    letter-spacing: 0.5px;
}
.detail-item p { font-size: 14px; color: var(--gray-800); margin-top: 2px; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .sidebar { width: 60px; }
    .sidebar-header h1, .sidebar-header p,
    .sidebar-nav a span:not(.icon),
    .sidebar-nav .section-label,
    .sidebar-footer .user-email,
    .sidebar-footer .user-role { display: none; }
    .sidebar-nav a { justify-content: center; padding: 12px; }
    .main-content { margin-left: 60px; padding: 16px; }
    .metric-grid { grid-template-columns: repeat(2, 1fr); }
    .split-panel { grid-template-columns: 1fr; }
    .topbar { flex-direction: column; gap: 12px; align-items: flex-start; }
}

@media (max-width: 480px) {
    .metric-grid { grid-template-columns: 1fr; }
    .filters { flex-direction: column; }
    .filters select, .filters input { width: 100%; }
}

/* ===== Print ===== */
@media print {
    .sidebar, .topbar-actions, .toast, .modal-overlay,
    #loading-screen, #access-denied, #login-screen,
    .bulk-bar, .pagination, .filters { display: none !important; }
    .main-content { margin-left: 0 !important; padding: 0 !important; }
    .card { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
    body { background: white; }
}
