/* ==========================================================================
   Al Hikmah Workspace - design system
   One stylesheet, no framework. Tokens first, then layout, then components.
   ========================================================================== */

/* ----------------------------------------------------------- tokens ----- */
:root {
  color-scheme: light;

  --bg:            #f6f7f9;
  --surface:       #ffffff;
  --surface-2:     #f2f4f7;
  --surface-3:     #e9edf2;
  --border:        #e3e8ef;
  --border-strong: #cfd6e0;

  --text:          #10151f;
  --text-muted:    #5b6675;
  --text-faint:    #8b95a4;

  --brand:         #0f766e;
  --brand-strong:  #0b5d56;
  --brand-soft:    #e6f4f1;
  --brand-text:    #0b5d56;

  --danger:        #b42318;
  --danger-soft:   #fef3f2;
  --warn:          #b54708;
  --warn-soft:     #fffaeb;
  --success:       #067647;
  --success-soft:  #ecfdf3;
  --info:          #175cd3;
  --info-soft:     #eff8ff;

  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 16px;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow:    0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-lg: 0 12px 32px -8px rgba(16, 24, 40, .18), 0 4px 12px -4px rgba(16, 24, 40, .08);

  --sidebar-w: 244px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --bg:            #0d1117;
  --surface:       #151b24;
  --surface-2:     #1c232e;
  --surface-3:     #242c38;
  --border:        #262e3a;
  --border-strong: #384252;

  --text:          #e8edf4;
  --text-muted:    #9aa6b6;
  --text-faint:    #6b7788;

  --brand:         #2dd4bf;
  --brand-strong:  #5eead4;
  --brand-soft:    #10312e;
  --brand-text:    #5eead4;

  --danger:        #fda29b;
  --danger-soft:   #3b1513;
  --warn:          #fdb022;
  --warn-soft:     #3a2408;
  --success:       #6ce9a6;
  --success-soft:  #0a2c1c;
  --info:          #84caff;
  --info-soft:     #0d2440;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow:    0 1px 3px rgba(0, 0, 0, .5);
  --shadow-lg: 0 16px 40px -12px rgba(0, 0, 0, .7);
}

/* ------------------------------------------------------------ reset ----- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.011em; line-height: 1.25; }
h1 { font-size: 24px; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }
p  { margin: 0 0 12px; }
p:last-child { margin-bottom: 0; }

a { color: var(--brand-text); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; }
code, kbd, pre { font-family: var(--mono); font-size: .92em; }

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Inline icons carry their own width/height; these only re-scale them.
   `flex: none` stops them being squashed by a flex sibling. */
.ah-icon { flex: none; display: inline-block; vertical-align: middle; }

.card__head > .ah-icon { width: 17px; height: 17px; color: var(--text-muted); }
.empty__icon .ah-icon  { width: 22px; height: 22px; }
.badge .ah-icon        { width: 13px; height: 13px; }
.table .ah-icon        { width: 15px; height: 15px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ----------------------------------------------------------- layout ----- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar__brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 18px 14px;
  font-weight: 700; font-size: 15px; letter-spacing: -.02em;
  color: var(--text);
}
.sidebar__brand:hover { text-decoration: none; }

.brand-mark {
  width: 30px; height: 30px; flex: none;
  border-radius: 9px;
  background: linear-gradient(140deg, var(--brand), var(--brand-strong));
  color: #fff;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 800;
}
:root[data-theme="dark"] .brand-mark { color: #04211e; }

.sidebar__nav { flex: 1; overflow-y: auto; padding: 4px 10px 12px; }

.nav-group { margin-top: 14px; }
.nav-group__label {
  padding: 0 8px 6px;
  font-size: 11px; font-weight: 650; letter-spacing: .06em;
  text-transform: uppercase; color: var(--text-faint);
}

.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; margin-bottom: 1px;
  border-radius: var(--radius-sm);
  color: var(--text-muted); font-weight: 500;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link.is-active { background: var(--brand-soft); color: var(--brand-text); font-weight: 600; }
.nav-link .ah-icon { width: 17px; height: 17px; }
.nav-link .count {
  margin-left: auto; font-size: 11px; font-weight: 600;
  background: var(--surface-3); color: var(--text-muted);
  padding: 1px 6px; border-radius: 999px;
}

.sidebar__footer { border-top: 1px solid var(--border); padding: 10px; }

.user-chip { display: flex; align-items: center; gap: 10px; padding: 6px 8px; }
.avatar {
  width: 30px; height: 30px; flex: none; border-radius: 50%;
  background: var(--surface-3); color: var(--text-muted);
  display: grid; place-items: center; font-size: 11px; font-weight: 700;
}
.user-chip__name { font-weight: 600; font-size: 13px; }
.user-chip__meta { font-size: 11px; color: var(--text-faint); }

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

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 20;
}
.topbar__title { font-size: 15px; font-weight: 650; }
.topbar__sub { font-size: 12px; color: var(--text-faint); }
.topbar__actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.content { padding: 24px; max-width: 1180px; width: 100%; }
.content--wide { max-width: none; }

.page-head { margin-bottom: 20px; }
.page-head p { color: var(--text-muted); margin-top: 4px; }

.menu-toggle { display: none; }

@media (max-width: 900px) {
  .shell { display: block; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 60;
    transform: translateX(-100%); transition: transform .18s ease;
    box-shadow: var(--shadow-lg);
  }
  body.nav-open .sidebar { transform: none; }
  body.nav-open::after {
    content: ""; position: fixed; inset: 0; z-index: 50;
    background: rgba(9, 12, 18, .45);
  }
  .menu-toggle { display: inline-flex; }
  .content { padding: 18px 16px; }
  .topbar { padding: 12px 16px; }
}

/* ---------------------------------------------------------- surfaces ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card__head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.card__head h3 { font-size: 14px; }
.card__head .card__actions { margin-left: auto; display: flex; gap: 8px; }
.card__body { padding: 18px; }
.card__body--flush { padding: 0; }
.card__note { padding: 10px 18px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-faint); }

.grid { display: grid; gap: 16px; }
.grid--apps  { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.grid--stats { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid--2     { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

.stack   { display: flex; flex-direction: column; gap: 16px; }
.row     { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row--end{ justify-content: flex-end; }
.spacer  { flex: 1; }

/* ------------------------------------------------------------ stats ----- */
.stat { padding: 16px 18px; }
.stat__label { font-size: 12px; color: var(--text-muted); font-weight: 550; }
.stat__value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 2px; }
.stat__hint  { font-size: 12px; color: var(--text-faint); margin-top: 2px; }

/* ---------------------------------------------------------- app card ---- */
.app-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: var(--shadow-sm);
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.app-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow); transform: translateY(-1px); }

.app-card__top { display: flex; align-items: flex-start; gap: 12px; }
.app-icon {
  width: 38px; height: 38px; flex: none;
  border-radius: 10px; object-fit: contain;
  background: var(--surface-2); padding: 5px;
  border: 1px solid var(--border);
}
.app-icon--fallback { display: grid; place-items: center; font-weight: 700; color: var(--text-muted); font-size: 14px; }
.app-card__name { font-weight: 650; font-size: 14px; }
.app-card__desc {
  font-size: 12.5px; color: var(--text-muted);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.app-card__foot { margin-top: auto; display: flex; gap: 8px; align-items: center; }

/* --------------------------------------------------------- controls ----- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 7px 13px;
  font: inherit; font-weight: 600; font-size: 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s ease, border-color .12s ease, opacity .12s ease;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn .ah-icon { width: 15px; height: 15px; }

.btn--primary {
  background: var(--brand); border-color: var(--brand); color: #fff;
}
.btn--primary:hover { background: var(--brand-strong); border-color: var(--brand-strong); }
:root[data-theme="dark"] .btn--primary { color: #04211e; }

.btn--danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn--danger:hover { background: var(--danger-soft); }

.btn--ghost { border-color: transparent; background: transparent; color: var(--text-muted); }
.btn--ghost:hover { background: var(--surface-2); color: var(--text); }

.btn--sm { padding: 4px 9px; font-size: 12px; }
.btn--block { width: 100%; }
.btn--icon { padding: 6px; }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field > label { font-size: 12.5px; font-weight: 600; color: var(--text); }
.field__hint { font-size: 11.5px; color: var(--text-faint); }

.input, .select, .textarea {
  width: 100%;
  padding: 8px 11px;
  font: inherit; font-size: 13.5px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: border-color .12s ease, box-shadow .12s ease;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent);
}
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.textarea { resize: vertical; min-height: 90px; font-family: var(--mono); font-size: 12.5px; line-height: 1.6; }
.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7788' d='M2.5 4.5 6 8l3.5-3.5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center; background-size: 12px;
  padding-right: 28px;
}

.input-group { display: flex; gap: 6px; }
.input-group .input { flex: 1; }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; }
.switch input { position: absolute; opacity: 0; }
.switch__track {
  width: 34px; height: 20px; border-radius: 999px;
  background: var(--surface-3); border: 1px solid var(--border-strong);
  position: relative; transition: background .15s ease, border-color .15s ease;
}
.switch__track::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--surface); box-shadow: var(--shadow-sm);
  transition: transform .15s ease;
}
.switch input:checked + .switch__track { background: var(--brand); border-color: var(--brand); }
.switch input:checked + .switch__track::after { transform: translateX(14px); }
.switch input:focus-visible + .switch__track { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ---------------------------------------------------------- feedback ---- */
.alert {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 11px 14px;
  border-radius: var(--radius);
  border: 1px solid;
  font-size: 13px;
  margin-bottom: 16px;
}
.alert .ah-icon { width: 17px; height: 17px; margin-top: 1px; }
.alert--info    { background: var(--info-soft);    border-color: color-mix(in srgb, var(--info) 30%, transparent);    color: var(--info); }
.alert--success { background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 30%, transparent); color: var(--success); }
.alert--warn    { background: var(--warn-soft);    border-color: color-mix(in srgb, var(--warn) 30%, transparent);    color: var(--warn); }
.alert--danger  { background: var(--danger-soft);  border-color: color-mix(in srgb, var(--danger) 30%, transparent);  color: var(--danger); }
.alert strong { font-weight: 650; }
.alert a { color: inherit; text-decoration: underline; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px;
  font-size: 11.5px; font-weight: 600;
  border-radius: 999px;
  background: var(--surface-2); color: var(--text-muted);
  border: 1px solid var(--border);
}
.badge--brand   { background: var(--brand-soft);   color: var(--brand-text); border-color: transparent; }
.badge--success { background: var(--success-soft); color: var(--success);    border-color: transparent; }
.badge--danger  { background: var(--danger-soft);  color: var(--danger);     border-color: transparent; }
.badge--warn    { background: var(--warn-soft);    color: var(--warn);       border-color: transparent; }
.badge--info    { background: var(--info-soft);    color: var(--info);       border-color: transparent; }

.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }

.empty { padding: 44px 24px; text-align: center; color: var(--text-muted); }
.empty h3 { margin-bottom: 6px; color: var(--text); }
.empty__icon {
  width: 44px; height: 44px; margin: 0 auto 12px;
  display: grid; place-items: center; border-radius: 12px;
  background: var(--surface-2); color: var(--text-faint);
}

/* ------------------------------------------------------------ table ----- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left; font-size: 11.5px; font-weight: 650;
  text-transform: uppercase; letter-spacing: .04em; color: var(--text-faint);
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  background: var(--surface-2); white-space: nowrap;
}
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table .num { font-variant-numeric: tabular-nums; }
.table .nowrap { white-space: nowrap; }

/* ----------------------------------------------------------- secret ----- */
.secret { display: inline-flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 12.5px; }
.secret__value {
  padding: 2px 7px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--border);
  letter-spacing: .05em; user-select: all;
}

/* ------------------------------------------------------------ modal ----- */
dialog.modal {
  width: min(680px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}
dialog.modal::backdrop { background: rgba(9, 12, 18, .55); backdrop-filter: blur(2px); }
.modal__head { display: flex; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal__head h3 { font-size: 15px; }
.modal__body { padding: 18px; max-height: min(70vh, 640px); overflow-y: auto; }
.modal__foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }

/* ------------------------------------------------------------ tabs ------ */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tab {
  padding: 9px 13px; font-size: 13px; font-weight: 600;
  color: var(--text-muted); border-bottom: 2px solid transparent;
  white-space: nowrap; cursor: pointer; background: none; border-top: 0; border-left: 0; border-right: 0;
  font-family: inherit;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab.is-active { color: var(--brand-text); border-bottom-color: var(--brand); }

/* ------------------------------------------------------------ auth ------ */
.auth {
  min-height: 100vh;
  display: grid; place-items: center;
  padding: 24px;
  background:
    radial-gradient(1000px 500px at 15% -10%, color-mix(in srgb, var(--brand) 12%, transparent), transparent 65%),
    var(--bg);
}
.auth__card { width: min(400px, 100%); }
.auth__brand { display: flex; align-items: center; gap: 10px; justify-content: center; margin-bottom: 20px; font-weight: 700; font-size: 16px; }
.auth__foot { text-align: center; margin-top: 18px; font-size: 12px; color: var(--text-faint); }

/* --------------------------------------------------------- utilities ---- */
.text-muted { color: var(--text-muted); }
.text-faint { color: var(--text-faint); }
.text-sm    { font-size: 12.5px; }
.text-xs    { font-size: 11.5px; }
.mono       { font-family: var(--mono); }
.truncate   { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mt-0 { margin-top: 0; }  .mt-2 { margin-top: 8px; }  .mt-3 { margin-top: 12px; }  .mt-4 { margin-top: 16px; }
.mb-0 { margin-bottom: 0; } .mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 16px; }
.hidden { display: none !important; }

@media print { .sidebar, .topbar__actions { display: none; } }
