/* frontend/css/app.css */

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

:root {
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --bg:          #f5f5f3;
  --surface:     #ffffff;
  --surface-2:   #f1efe8;
  --border:      rgba(0,0,0,0.09);
  --border-md:   rgba(0,0,0,0.16);
  --text:        #1a1a18;
  --text-2:      #5f5e5a;
  --text-3:      #989690;
  --green:       #1D9E75;
  --green-dark:  #0F6E56;
  --green-light: #E1F5EE;
  --red:         #E24B4A;
  --radius:      8px;
  --radius-lg:   12px;
  --sidebar-w:   220px;
  --topbar-h:    52px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:          #181816;
    --surface:     #222220;
    --surface-2:   #2a2a28;
    --border:      rgba(255,255,255,0.08);
    --border-md:   rgba(255,255,255,0.15);
    --text:        #f1efe8;
    --text-2:      #b4b2a9;
    --text-3:      #787670;
    --green-light: #04342C;
  }
}

body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
a { text-decoration: none; color: inherit; }
button { font-family: var(--font); cursor: pointer; }
input, select, textarea { font-family: var(--font); }

/* ── Auth ── */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--bg); padding: 1rem;
}
.auth-card {
  background: var(--surface); border: 0.5px solid var(--border-md);
  border-radius: var(--radius-lg); padding: 2rem; width: 100%; max-width: 380px;
}
.auth-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 1.75rem; }
.auth-logo-mark {
  width: 36px; height: 36px; border-radius: 10px; background: var(--green);
  display: flex; align-items: center; justify-content: center;
}
.auth-logo-mark i { color: #fff; font-size: 18px; }
.auth-logo-name { font-size: 20px; font-weight: 500; }
.auth-logo-name span { color: var(--green); }
.auth-title { font-size: 17px; font-weight: 500; margin-bottom: 4px; }
.auth-sub   { font-size: 13px; color: var(--text-2); margin-bottom: 1.5rem; }
.auth-field { margin-bottom: 12px; }
.auth-label { font-size: 12px; color: var(--text-2); margin-bottom: 4px; display: block; }
.auth-input {
  width: 100%; padding: 9px 12px; border-radius: var(--radius);
  border: 0.5px solid var(--border-md); background: var(--surface-2);
  color: var(--text); font-size: 14px; outline: none; transition: border-color 0.15s;
}
.auth-input:focus { border-color: var(--green); }
.auth-btn {
  width: 100%; padding: 10px; background: var(--green); color: #fff;
  border: none; border-radius: var(--radius); font-size: 14px; font-weight: 500;
  margin-top: 8px; transition: background 0.15s;
}
.auth-btn:hover { background: var(--green-dark); }
.auth-switch { font-size: 13px; color: var(--text-2); text-align: center; margin-top: 1rem; }
.auth-switch a { color: var(--green); font-weight: 500; cursor: pointer; }
.auth-error { background: #FAECE7; color: #993C1D; border-radius: var(--radius); padding: 8px 12px; font-size: 13px; margin-bottom: 12px; }

/* ── App shell ── */
#app { display: none; }
.app-layout { display: flex; height: 100vh; overflow: hidden; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--surface); border-right: 0.5px solid var(--border);
  display: flex; flex-direction: column; overflow-y: auto;
}
.sidebar-logo {
  display: flex; align-items: center; gap: 9px; padding: 1rem 1.25rem;
  border-bottom: 0.5px solid var(--border);
}
.sidebar-logo-mark {
  width: 30px; height: 30px; border-radius: 8px; background: var(--green);
  display: flex; align-items: center; justify-content: center;
}
.sidebar-logo-mark i { color: #fff; font-size: 16px; }
.sidebar-logo-name { font-size: 16px; font-weight: 500; }
.sidebar-logo-name span { color: var(--green); }

.sidebar-section { padding: 1rem 0.75rem 0.5rem; }
.sidebar-section-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.7px; color: var(--text-3); padding: 0 0.5rem; margin-bottom: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 9px; padding: 8px 10px;
  border-radius: var(--radius); font-size: 13px; color: var(--text-2);
  cursor: pointer; border: none; background: transparent; width: 100%;
  text-align: left; transition: all 0.15s; margin-bottom: 2px;
}
.nav-item i { font-size: 16px; flex-shrink: 0; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--green-light); color: var(--green-dark); font-weight: 500; }
.nav-item .badge-count {
  margin-left: auto; background: var(--red); color: #fff;
  border-radius: 20px; font-size: 10px; padding: 1px 6px; font-weight: 500;
}

.sidebar-bottom { margin-top: auto; padding: 0.75rem; border-top: 0.5px solid var(--border); }
.user-pill {
  display: flex; align-items: center; gap: 9px; padding: 8px 10px;
  border-radius: var(--radius); background: var(--surface-2);
}
.user-avatar {
  width: 28px; height: 28px; border-radius: 50%; background: #E6F1FB;
  color: #185FA5; font-size: 11px; font-weight: 500;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.user-name  { font-size: 12px; font-weight: 500; }
.user-role  { font-size: 11px; color: var(--text-3); }
.logout-btn {
  margin-left: auto; border: none; background: transparent;
  color: var(--text-3); padding: 4px; cursor: pointer; border-radius: 4px;
}
.logout-btn:hover { color: var(--red); }

/* Main content */
.main-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  height: var(--topbar-h); flex-shrink: 0;
  border-bottom: 0.5px solid var(--border);
  padding: 0 1.5rem; display: flex; align-items: center; justify-content: space-between;
  background: var(--surface);
}
.topbar-title { font-size: 15px; font-weight: 500; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

.page-content { flex: 1; overflow-y: auto; padding: 1.5rem; }

/* ── Reusable components ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: var(--radius); font-size: 13px; font-weight: 500;
  border: 0.5px solid var(--border-md); background: var(--surface); color: var(--text);
  transition: background 0.15s; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--green); color: #fff; border-color: var(--green); }
.btn-primary:hover { background: var(--green-dark); border-color: var(--green-dark); }
.btn-danger { background: var(--red); color: #fff; border-color: var(--red); }
.btn-danger:hover { filter: brightness(0.9); }
.btn-sm { padding: 4px 10px; font-size: 12px; }

.metrics-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 12px; margin-bottom: 1.5rem; }
.metric-card { background: var(--surface); border: 0.5px solid var(--border); border-radius: var(--radius-lg); padding: 1rem 1.25rem; }
.metric-label { font-size: 12px; color: var(--text-2); margin-bottom: 6px; display: flex; align-items: center; gap: 5px; }
.metric-value { font-size: 22px; font-weight: 500; letter-spacing: -0.4px; }
.metric-delta { font-size: 12px; color: var(--text-3); margin-top: 4px; }

.panel { background: var(--surface); border: 0.5px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.panel-hd {
  padding: 0.85rem 1.25rem; border-bottom: 0.5px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.panel-title { font-size: 14px; font-weight: 500; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; color: var(--text-3); padding: 0.6rem 1.25rem; border-bottom: 0.5px solid var(--border); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 500; }
td { padding: 0.8rem 1.25rem; border-bottom: 0.5px solid var(--border); font-size: 13px; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface-2); }

.field { margin-bottom: 12px; }
.label { font-size: 12px; color: var(--text-2); margin-bottom: 4px; display: block; }
.input, .select, .textarea {
  width: 100%; padding: 8px 10px; border-radius: var(--radius);
  border: 0.5px solid var(--border-md); background: var(--surface-2);
  color: var(--text); font-size: 13px; outline: none; transition: border-color 0.15s;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--green); }
.textarea { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 100;
  display: none; align-items: center; justify-content: center; padding: 1rem;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface); border-radius: var(--radius-lg);
  width: 100%; max-width: 520px; max-height: 85vh; display: flex; flex-direction: column;
  box-shadow: 0 8px 40px rgba(0,0,0,0.18);
}
.modal-hd {
  padding: 1rem 1.25rem; border-bottom: 0.5px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; flex-shrink: 0;
}
.modal-hd h3 { font-size: 15px; font-weight: 500; }
.modal-close { border: none; background: transparent; font-size: 18px; cursor: pointer; color: var(--text-3); padding: 2px; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 1.25rem; overflow-y: auto; flex: 1; }
.modal-footer { padding: 1rem 1.25rem; border-top: 0.5px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; flex-shrink: 0; }

/* ── Toast ── */
.toast {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  background: var(--surface); border: 0.5px solid var(--border);
  border-left: 3px solid var(--green); border-radius: var(--radius);
  padding: 0.7rem 1rem; font-size: 13px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.1);
  display: flex; align-items: center; gap: 8px; z-index: 200;
  animation: slideUp 0.25s ease;
}
.toast.hide { animation: slideDown 0.25s ease forwards; }
@keyframes slideUp   { from { transform: translateY(16px); opacity: 0; } }
@keyframes slideDown { to   { transform: translateY(16px); opacity: 0; } }

/* ── Loading ── */
.loading { text-align: center; padding: 2rem; color: var(--text-3); font-size: 13px; }

/* ── Filter bar ── */
.filter-bar { display: flex; gap: 8px; padding: 0.75rem 1.25rem; background: var(--surface-2); border-bottom: 0.5px solid var(--border); flex-wrap: wrap; align-items: center; }
.chip { padding: 4px 12px; border-radius: 20px; font-size: 12px; cursor: pointer; border: 0.5px solid var(--border-md); background: transparent; color: var(--text-2); transition: all 0.15s; }
.chip.active { background: var(--green); color: #fff; border-color: var(--green); }
.chip:hover:not(.active) { background: var(--surface); }
.search-box {
  display: flex; align-items: center; gap: 6px; padding: 0 1.25rem 0.75rem;
  border-bottom: 0.5px solid var(--border);
}
.search-box i { color: var(--text-3); font-size: 15px; }
.search-box input { border: none; background: transparent; font-size: 13px; color: var(--text); outline: none; flex: 1; font-family: var(--font); }
.search-box input::placeholder { color: var(--text-3); }

/* ── Charts ── */
.chart-container { padding: 1rem 1.25rem; }

/* ── Responsive ── */
@media (max-width: 900px) {
  .sidebar { display: none; }
  .metrics-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
  .metrics-grid { grid-template-columns: 1fr 1fr; }
  .page-content { padding: 1rem; }
}
