/* ═══ RESET & BASE ═══ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #ffffff;
  --bg2: #f7f6f3;
  --bg3: #f0ede8;
  --text: #1a1917;
  --text2: #6b6a66;
  --text3: #a09f9b;
  --border: rgba(0,0,0,0.1);
  --border2: rgba(0,0,0,0.18);
  --blue: #185FA5;
  --blue-light: #E6F1FB;
  --blue-dark: #0C447C;
  --green: #1D9E75;
  --green-light: #EAF3DE;
  --amber: #BA7517;
  --amber-light: #FAEEDA;
  --red: #A32D2D;
  --red-light: #FCEBEB;
  --gray-light: #F1EFE8;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1917;
    --bg2: #242320;
    --bg3: #2e2c29;
    --text: #f0ede8;
    --text2: #9b9a96;
    --text3: #6b6a66;
    --border: rgba(255,255,255,0.1);
    --border2: rgba(255,255,255,0.18);
    --blue-light: #0c2a47;
    --green-light: #0d3020;
    --amber-light: #3a2508;
    --red-light: #3a0f0f;
    --gray-light: #2e2c29;
  }
}

body { font-family: -apple-system, 'Segoe UI', system-ui, sans-serif; font-size: 14px; color: var(--text); background: var(--bg3); line-height: 1.5; }

/* ═══ LOGIN ═══ */
#login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg3); }
.login-box { background: var(--bg); border: 0.5px solid var(--border); border-radius: var(--radius-lg); padding: 40px; width: 360px; }
.login-logo { text-align: center; margin-bottom: 28px; }
.login-icon { font-size: 32px; color: var(--blue); margin-bottom: 8px; }
.login-logo h1 { font-size: 22px; font-weight: 600; }
.login-logo p { color: var(--text2); font-size: 13px; margin-top: 4px; }
.error-msg { color: var(--red); font-size: 12px; margin-bottom: 12px; min-height: 16px; }

/* ═══ LAYOUT ═══ */
#app { display: flex; height: 100vh; overflow: hidden; }
#sidebar { width: 212px; min-width: 212px; background: var(--bg); border-right: 0.5px solid var(--border); display: flex; flex-direction: column; }
#main { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: var(--bg3); }
#topbar { padding: 14px 24px; background: var(--bg); border-bottom: 0.5px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
#topbar h2 { font-size: 16px; font-weight: 600; }
#breadcrumb { font-size: 12px; color: var(--text3); margin-top: 1px; }
#topbar-actions { display: flex; gap: 8px; align-items: center; }
#content { flex: 1; overflow-y: auto; padding: 24px; }

/* ═══ SIDEBAR ═══ */
.logo { padding: 16px 14px; border-bottom: 0.5px solid var(--border); display: flex; align-items: center; gap: 10px; }
.logo-icon { font-size: 20px; color: var(--blue); }
.logo-title { font-size: 14px; font-weight: 600; }
.logo-sub { font-size: 11px; color: var(--text3); }
.nav { flex: 1; overflow-y: auto; padding: 8px 6px; }
.nav-section-label { font-size: 10px; font-weight: 600; color: var(--text3); text-transform: uppercase; letter-spacing: 0.07em; padding: 10px 8px 4px; }
.nav-item { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; border: none; background: none; border-radius: 6px; cursor: pointer; font-size: 13px; color: var(--text2); text-align: left; transition: all 0.1s; }
.nav-item:hover { background: var(--bg2); color: var(--text); }
.nav-item.active { background: var(--blue-light); color: var(--blue-dark); font-weight: 500; }
.nav-ico { font-size: 13px; width: 16px; text-align: center; }
.sidebar-footer { padding: 12px 14px; border-top: 0.5px solid var(--border); display: flex; align-items: center; gap: 8px; }
.user-info { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; }
.user-avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--blue-light); color: var(--blue-dark); display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; flex-shrink: 0; }
.user-name { font-size: 12px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--text3); }
.btn-logout { background: none; border: none; cursor: pointer; font-size: 16px; color: var(--text3); padding: 4px; border-radius: 4px; }
.btn-logout:hover { color: var(--red); background: var(--red-light); }

/* ═══ PAGES ═══ */
.page { display: none; }
.page.active { display: block; }

/* ═══ KPI CARDS ═══ */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi { background: var(--bg); border: 0.5px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.kpi-label { font-size: 11px; color: var(--text3); margin-bottom: 6px; }
.kpi-value { font-size: 22px; font-weight: 600; line-height: 1; }
.kpi-sub { font-size: 11px; color: var(--text2); margin-top: 4px; }
.kpi-value.danger { color: var(--red); }
.kpi-value.success { color: var(--green); }

/* ═══ CARD ═══ */
.card { background: var(--bg); border: 0.5px solid var(--border); border-radius: var(--radius-lg); padding: 16px 20px; margin-bottom: 16px; }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-title { font-size: 14px; font-weight: 600; }
.card-subtitle { font-size: 12px; color: var(--text2); margin-top: 1px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }

/* ═══ TABLE ═══ */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { font-size: 11px; font-weight: 600; color: var(--text3); text-align: left; padding: 8px 12px; border-bottom: 0.5px solid var(--border); white-space: nowrap; text-transform: uppercase; letter-spacing: 0.04em; }
td { font-size: 13px; padding: 11px 12px; border-bottom: 0.5px solid var(--border); color: var(--text); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--bg2); }
.td-muted { color: var(--text2); font-size: 12px; }

/* ═══ BADGES ═══ */
.badge { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 500; white-space: nowrap; }
.badge-blue { background: var(--blue-light); color: var(--blue-dark); }
.badge-green { background: var(--green-light); color: #27500A; }
.badge-amber { background: var(--amber-light); color: #633806; }
.badge-red { background: var(--red-light); color: #791F1F; }
.badge-gray { background: var(--gray-light); color: #444441; }

/* ═══ PROGRESS ═══ */
.progress { background: var(--bg2); border-radius: 4px; height: 6px; overflow: hidden; min-width: 80px; }
.progress-fill { height: 100%; border-radius: 4px; background: var(--blue); }

/* ═══ BUTTONS ═══ */
.btn { padding: 7px 16px; border-radius: var(--radius); border: 0.5px solid var(--border2); background: var(--bg); color: var(--text); cursor: pointer; font-size: 13px; font-family: inherit; transition: all 0.1s; white-space: nowrap; }
.btn:hover { background: var(--bg2); }
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn-primary:hover { background: var(--blue-dark); }
.btn-danger { background: var(--red); color: #fff; border-color: var(--red); }
.btn-danger:hover { background: #791F1F; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; margin-top: 4px; }
.btn-icon { padding: 6px; border: none; background: none; cursor: pointer; color: var(--text3); border-radius: 4px; }
.btn-icon:hover { background: var(--bg2); color: var(--text); }
.actions { display: flex; gap: 4px; align-items: center; }

/* ═══ FORMS ═══ */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.full { grid-column: 1 / -1; }
label { font-size: 12px; font-weight: 500; color: var(--text2); }
input, select, textarea { padding: 8px 10px; border-radius: var(--radius); border: 0.5px solid var(--border2); background: var(--bg); color: var(--text); font-size: 13px; font-family: inherit; width: 100%; transition: border 0.1s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(24,95,165,0.1); }
textarea { resize: vertical; min-height: 80px; }
input[type="number"] { -moz-appearance: textfield; }

/* ═══ MODAL ═══ */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 200; display: none; align-items: center; justify-content: center; padding: 20px; }
.modal-backdrop.open { display: flex; }
.modal { background: var(--bg); border-radius: var(--radius-lg); border: 0.5px solid var(--border); width: 580px; max-width: 100%; max-height: 90vh; overflow-y: auto; }
.modal-header { padding: 16px 20px; border-bottom: 0.5px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { font-size: 15px; font-weight: 600; }
.modal-close { background: none; border: none; cursor: pointer; font-size: 16px; color: var(--text3); padding: 4px; }
.modal-body { padding: 20px; }
.modal-footer { padding: 14px 20px; border-top: 0.5px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* ═══ TOAST ═══ */
#toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 300; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 12px 16px; border-radius: var(--radius); background: var(--text); color: var(--bg); font-size: 13px; min-width: 200px; animation: slideIn 0.2s ease; }
.toast.success { background: #27500A; }
.toast.error { background: var(--red); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ═══ GANTT ═══ */
.gantt-wrap { border: 0.5px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; background: var(--bg); }
.gantt-head { display: flex; border-bottom: 0.5px solid var(--border); background: var(--bg2); }
.g-label-col { width: 220px; min-width: 220px; padding: 10px 14px; font-size: 11px; font-weight: 600; color: var(--text3); text-transform: uppercase; letter-spacing: 0.04em; border-right: 0.5px solid var(--border); }
.g-timeline-header { flex: 1; position: relative; height: 40px; overflow: hidden; }
.g-row { display: flex; border-bottom: 0.5px solid var(--border); min-height: 46px; }
.g-row:last-child { border-bottom: none; }
.g-label { width: 220px; min-width: 220px; padding: 8px 14px; border-right: 0.5px solid var(--border); cursor: pointer; display: flex; flex-direction: column; justify-content: center; }
.g-label:hover { background: var(--bg2); }
.g-row-title { font-size: 12px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.g-row-sub { font-size: 11px; color: var(--text3); margin-top: 1px; }
.g-bars { flex: 1; position: relative; overflow: hidden; }
.g-bar { position: absolute; top: 10px; height: 26px; border-radius: 4px; display: flex; align-items: center; overflow: hidden; cursor: pointer; }
.g-bar:hover { filter: brightness(0.9); }
.g-bar-progress { position: absolute; left: 0; top: 0; height: 100%; background: rgba(255,255,255,0.3); border-radius: 4px; }
.g-bar-label { position: relative; z-index: 1; font-size: 11px; font-weight: 500; color: #fff; padding: 0 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.g-sub-row { display: flex; min-height: 34px; background: var(--bg2); border-bottom: 0.5px solid var(--border); }
.g-sub-label { width: 220px; min-width: 220px; padding: 4px 14px 4px 30px; border-right: 0.5px solid var(--border); font-size: 11px; color: var(--text2); display: flex; align-items: center; }
.g-today { position: absolute; top: 0; bottom: 0; width: 1.5px; background: #E24B4A; z-index: 5; pointer-events: none; }
.g-month-line { position: absolute; top: 0; bottom: 0; width: 0.5px; background: var(--border); pointer-events: none; }
.g-month-label { position: absolute; font-size: 10px; color: var(--text3); padding: 2px 4px; white-space: nowrap; pointer-events: none; }

/* ═══ DETAIL VIEW ═══ */
.detail-back { display: flex; align-items: center; gap: 8px; margin-bottom: 20px; cursor: pointer; color: var(--text2); font-size: 13px; border: none; background: none; padding: 4px 0; }
.detail-back:hover { color: var(--text); }
.detail-header { background: var(--bg); border: 0.5px solid var(--border); border-radius: var(--radius-lg); padding: 20px 24px; margin-bottom: 16px; }
.detail-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 16px; margin-top: 16px; }
.df-label { font-size: 11px; color: var(--text3); margin-bottom: 2px; }
.df-value { font-size: 13px; font-weight: 500; }

/* ═══ EMPTY STATE ═══ */
.empty-state { text-align: center; padding: 48px 20px; color: var(--text3); }
.empty-state-icon { font-size: 32px; margin-bottom: 12px; }
.empty-state p { font-size: 13px; }

/* ═══ CHART BARS (horizontal) ═══ */
.hbar-wrap { background: var(--bg2); border-radius: 4px; height: 8px; overflow: hidden; flex: 1; }
.hbar-fill { height: 100%; border-radius: 4px; background: var(--blue); }
.stat-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 0.5px solid var(--border); }
.stat-row:last-child { border-bottom: none; }
.stat-label { font-size: 12px; min-width: 120px; max-width: 120px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-val { font-size: 12px; min-width: 70px; text-align: right; }

/* ═══ TABS ═══ */
.tabs { display: flex; gap: 2px; padding: 3px; background: var(--bg2); border-radius: var(--radius); width: fit-content; margin-bottom: 16px; }
.tab { padding: 6px 14px; border-radius: 6px; cursor: pointer; font-size: 13px; color: var(--text2); border: none; background: none; font-family: inherit; }
.tab.active { background: var(--bg); color: var(--text); font-weight: 500; box-shadow: var(--shadow); }

/* ═══ DOCS ═══ */
.doc-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 0.5px solid var(--border); }
.doc-item:last-child { border-bottom: none; }
.doc-icon { width: 34px; height: 34px; border-radius: 6px; background: var(--blue-light); color: var(--blue-dark); display: flex; align-items: center; justify-content: center; font-size: 14px; flex-shrink: 0; }
.doc-name { font-size: 13px; font-weight: 500; }
.doc-meta { font-size: 11px; color: var(--text3); }

/* ═══ UPLOAD ═══ */
.upload-zone { border: 1.5px dashed var(--border2); border-radius: var(--radius); padding: 24px; text-align: center; cursor: pointer; transition: all 0.1s; }
.upload-zone:hover { border-color: var(--blue); background: var(--blue-light); }
.upload-zone.dragover { border-color: var(--blue); background: var(--blue-light); }

/* ═══ ONEDRIVE ═══ */
.onedrive-badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; background: #E6F1FB; color: #0C447C; border-radius: 4px; font-size: 11px; }

/* ═══ SCROLLBAR ═══ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
