:root {
  --primary: #1F3B57;
  --primary-light: #2C4E73;
  --accent: #1F6B63;
  --accent-light: #e6f1ef;
  --bg: #F4F6F8;
  --surface: #FFFFFF;
  --border: #E2E5EA;
  --text: #1B2733;
  --muted: #64707D;
  --success: #1F8A5B;
  --success-bg: #e8f6ef;
  --warning: #B05A00;
  --warning-bg: #fdf1e6;
  --danger: #B0231F;
  --module-blue: #1E4C8C;
  --module-blue-bg: #e9eff8;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.06);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

/* ---------- Preview banner ---------- */
.preview-banner {
  flex-shrink: 0;
  background: var(--warning-bg);
  color: var(--warning);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  padding: 7px 12px;
  border-bottom: 1px solid #f0d9bd;
  letter-spacing: .2px;
}

/* ---------- Login page ---------- */
.login-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 40px 32px;
  text-align: center;
}
.login-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 28px;
}
.login-brand .mark {
  width: 36px; height: 36px;
  border-radius: 9px;
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px;
}
.login-brand .name { font-weight: 700; font-size: 18px; color: var(--primary); }
.login-card h1 { font-size: 20px; margin: 0 0 6px; }
.login-card p.sub { color: var(--muted); font-size: 14px; margin: 0 0 28px; }

.btn-o365 {
  width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: box-shadow .15s, border-color .15s;
}
.btn-o365:hover { border-color: #c7cdd6; box-shadow: var(--shadow); }
.login-foot { margin-top: 22px; font-size: 12px; color: var(--muted); }

.login-divider { display: flex; align-items: center; gap: 12px; margin: 20px 0; color: var(--muted); font-size: 12px; }
.login-divider::before, .login-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.local-login-form { text-align: left; display: flex; flex-direction: column; gap: 14px; }
.local-login-form .field input { width: 100%; }
.login-error { color: var(--danger); font-size: 12.5px; margin: -6px 0 0; }
.local-login-form p.hint { font-size: 12px; color: var(--muted); margin: -6px 0 0; }

/* ---------- App shell ---------- */
.shell { display: flex; flex: 1; min-height: 0; }

.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--primary);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  overflow-y: auto;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px 22px;
}
.sidebar .brand .mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: rgba(255,255,255,.15);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px;
}
.sidebar .brand .name { font-weight: 700; font-size: 16px; }

.nav-section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: rgba(255,255,255,.5);
  padding: 16px 10px 6px;
}
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px;
  border-radius: 7px;
  font-size: 14px;
  color: rgba(255,255,255,.85);
  cursor: pointer;
  margin-bottom: 2px;
}
.nav-link svg { width: 17px; height: 17px; flex-shrink: 0; }
.nav-link:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-link.active { background: rgba(255,255,255,.16); color: #fff; font-weight: 600; }
.nav-link.sub { padding-left: 32px; font-size: 13.5px; }
.nav-link-ext { justify-content: space-between; }
.nav-link-ext .ext { opacity: .6; font-size: 12px; }

.sidebar-foot {
  margin-top: auto;
  padding: 10px;
  font-size: 11.5px;
  color: rgba(255,255,255,.45);
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 0; }

.topbar {
  height: 60px;
  flex-shrink: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
}
.topbar .page-title { font-size: 16px; font-weight: 700; }
.user-menu { position: relative; }
.user-chip {
  display: flex; align-items: center; gap: 10px;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 8px;
}
.user-chip:hover { background: var(--bg); }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent);
  color: #fff; font-weight: 700; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
}
.user-chip .who { font-size: 13.5px; line-height: 1.25; }
.user-chip .who .name { font-weight: 600; }
.user-chip .who .role { color: var(--muted); font-size: 11.5px; }
.user-dropdown {
  position: absolute; right: 0; top: 46px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  width: 180px;
  padding: 6px;
  display: none;
  z-index: 20;
}
.user-dropdown.open { display: block; }
.user-dropdown a, .user-dropdown button {
  display: block; width: 100%; text-align: left;
  background: none; border: none; padding: 8px 10px;
  border-radius: 6px; font-size: 13.5px; cursor: pointer; color: var(--text);
}
.user-dropdown a:hover, .user-dropdown button:hover { background: var(--bg); }

.content { flex: 1; min-height: 0; padding: 28px 32px; overflow-y: auto; }
.view { display: none; }
.view.active { display: block; }

.view-header { margin-bottom: 22px; }
.view-header h2 { margin: 0 0 4px; font-size: 22px; }
.view-header p { margin: 0; color: var(--muted); font-size: 14px; }

/* ---------- Cards / modules ---------- */
.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.module-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.module-card .icon {
  width: 40px; height: 40px; border-radius: 9px;
  background: var(--module-blue-bg);
  color: var(--module-blue);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 14px;
}
.module-card .icon svg { width: 20px; height: 20px; }
.module-card h3 { margin: 0 0 4px; font-size: 15.5px; }
.module-card p { margin: 0 0 16px; font-size: 13px; color: var(--muted); line-height: 1.45; }
.module-card .open-btn {
  font-size: 13px; font-weight: 600; color: var(--module-blue);
  cursor: pointer;
}
.module-card.add-module {
  border: 1.5px dashed #c7cdd6;
  box-shadow: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--muted);
  cursor: pointer;
  min-height: 158px;
  text-align: center;
}
.module-card.add-module:hover { border-color: var(--accent); color: var(--accent); }
.module-card.add-module .icon { background: transparent; color: inherit; }

/* ---------- Settings layout ---------- */
.settings-tabs {
  display: flex; gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.settings-tab {
  padding: 10px 4px;
  margin-right: 20px;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.settings-tab.active { color: var(--primary); font-weight: 600; border-color: var(--accent); }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
}
.panel h3 { margin: 0 0 4px; font-size: 15px; }
.panel .panel-sub { margin: 0 0 18px; font-size: 13px; color: var(--muted); }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px 20px;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--text); }
.field .hint { font-size: 11.5px; color: var(--muted); }
.field input[type=text], .field input[type=password], .field select {
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 13.5px;
  background: #fff;
  color: var(--text);
}
.field input:focus, .field select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.row-actions { display: flex; gap: 10px; margin-top: 18px; }

.btn {
  padding: 9px 16px;
  border-radius: 7px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-light); }
.btn-secondary { background: #fff; border-color: var(--border); color: var(--text); }
.btn-secondary:hover { border-color: #c7cdd6; }
.btn-danger-outline { background: #fff; border-color: #f0c9c8; color: var(--danger); }

/* toggle switch */
.switch-row { display: flex; align-items: center; justify-content: space-between; padding: 4px 0; }
.switch-row + .switch-row { border-top: 1px solid var(--border); }
.switch-row .label { font-size: 13.5px; font-weight: 600; }
.switch-row .desc { font-size: 12px; color: var(--muted); margin-top: 2px; }
.switch { position: relative; width: 40px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0; background: #cfd5dc; border-radius: 999px;
  transition: background .15s; cursor: pointer;
}
.switch .track::before {
  content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: transform .15s;
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::before { transform: translateX(18px); }

/* status pills */
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.pill-success { background: var(--success-bg); color: var(--success); }
.pill-warning { background: var(--warning-bg); color: var(--warning); }
.pill-muted { background: var(--bg); color: var(--muted); }
.pill svg { width: 10px; height: 10px; }

/* tables */
table.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data-table th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--border);
}
table.data-table td { padding: 11px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data-table tr:last-child td { border-bottom: none; }
.table-actions { display: flex; gap: 14px; }
.table-actions span { font-size: 12.5px; font-weight: 600; color: var(--accent); cursor: pointer; }
.table-actions span.danger { color: var(--danger); }

.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--accent-light); color: var(--accent); font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; margin: 2px 4px 2px 0; }

/* toast */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(12px);
  background: #1B2733; color: #fff; padding: 11px 18px; border-radius: 8px;
  font-size: 13.5px; box-shadow: 0 8px 24px rgba(0,0,0,.2);
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s;
  z-index: 100;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.two-col { display: grid; grid-template-columns: 1.3fr 1fr; gap: 20px; }
@media (max-width: 860px) { .two-col { grid-template-columns: 1fr; } }

.stat-row { display: flex; gap: 24px; flex-wrap: wrap; margin-bottom: 4px; }
.stat { min-width: 120px; }
.stat .num { font-size: 22px; font-weight: 700; }
.stat .lbl { font-size: 12px; color: var(--muted); }

/* ---- Setup guide (collapsible, in-page step-by-step) ---- */
.guide-panel summary { cursor: pointer; list-style: none; display: flex; align-items: center; justify-content: space-between; padding: 4px 0; }
.guide-panel summary::-webkit-details-marker { display: none; }
.guide-panel summary h3 { margin: 0; }
.guide-panel summary .guide-toggle-hint { font-size: 12px; color: var(--accent); font-weight: 600; }
.guide-panel[open] summary .guide-toggle-hint::after { content: "Hide guide"; }
.guide-panel:not([open]) summary .guide-toggle-hint::after { content: "Show guide"; }
.guide-panel .panel-sub { margin-top: 4px; }
.guide-steps { list-style: none; margin: 18px 0 0; padding: 0; counter-reset: guide-step; }
.guide-steps > li { position: relative; padding: 0 0 20px 34px; counter-increment: guide-step; }
.guide-steps > li::before {
  content: counter(guide-step);
  position: absolute; left: 0; top: 0;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent-light); color: var(--accent);
  font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.guide-steps > li:not(:last-child) { border-left: 1px solid var(--border); margin-left: 10px; }
.guide-steps > li:not(:last-child)::before { margin-left: -11px; }
.guide-steps > li:last-child::before { margin-left: -11px; }
.guide-steps .step-title { font-weight: 600; font-size: 13.5px; margin-bottom: 3px; }
.guide-steps .step-body { font-size: 13px; color: var(--muted); line-height: 1.5; }
.guide-steps .step-body code { background: var(--bg); border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px; font-size: 12px; color: var(--text); }
.guide-note { margin-top: 4px; font-size: 12.5px; background: var(--warning-bg); color: var(--warning); border-radius: 6px; padding: 8px 10px; }
.guide-note.done { background: var(--success-bg); color: var(--success); }
