/* ISO/IEC 42001 AIMS Manager - themes via CSS variables */
:root, [data-theme="light"] {
  --bg: #f3f5fa; --surface: #ffffff; --surface2: #eef1f8; --text: #1b2540; --muted: #66708b; --border: #dbe0ee;
  --primary: #2f5bea; --primary-text: #ffffff; --accent: #12a4b8; --good: #1f9d63; --warn: #e0a100; --bad: #d64545; --info: #3b82c4;
  --side-bg: #14213d; --side-text: #cfd8ee; --side-active: #2f5bea; --shadow: 0 2px 10px rgba(20, 33, 61, .08);
}
[data-theme="dark"] {
  --bg: #0e1320; --surface: #172033; --surface2: #1e2942; --text: #e7ebf6; --muted: #98a3c0; --border: #2b3856;
  --primary: #6c8cff; --primary-text: #0b1020; --accent: #3cc8d9; --good: #3ecf8e; --warn: #f0b429; --bad: #ff6b6b; --info: #62a8ee;
  --side-bg: #0a0f1a; --side-text: #b9c3dd; --side-active: #3a56b8; --shadow: 0 2px 12px rgba(0, 0, 0, .4);
}
[data-theme="ocean"] {
  --bg: #e9f5f9; --surface: #ffffff; --surface2: #dff0f6; --text: #0d3040; --muted: #56788a; --border: #c5e0ea;
  --primary: #0a7ea4; --primary-text: #fff; --accent: #f08a24; --good: #14966b; --warn: #d99a00; --bad: #cf4040; --info: #2b7bb9;
  --side-bg: #06384c; --side-text: #bfe3ef; --side-active: #0a7ea4; --shadow: 0 2px 10px rgba(6, 56, 76, .1);
}
[data-theme="forest"] {
  --bg: #edf4ee; --surface: #ffffff; --surface2: #e1eee3; --text: #1b3326; --muted: #5d7a68; --border: #cfe0d3;
  --primary: #2c7a4b; --primary-text: #fff; --accent: #b8860b; --good: #2c9a5b; --warn: #d19a00; --bad: #c94a3a; --info: #3a84a8;
  --side-bg: #153526; --side-text: #c6e2cf; --side-active: #2c7a4b; --shadow: 0 2px 10px rgba(21, 53, 38, .1);
}
[data-theme="sunset"] {
  --bg: #fff3ea; --surface: #ffffff; --surface2: #ffe6d6; --text: #3a1d24; --muted: #8a6169; --border: #f3d3c0;
  --primary: #dd5a1e; --primary-text: #fff; --accent: #b0306a; --good: #2e9a64; --warn: #d79500; --bad: #c8333f; --info: #3b7fb8;
  --side-bg: #3b1a2d; --side-text: #f2d4c7; --side-active: #dd5a1e; --shadow: 0 2px 10px rgba(59, 26, 45, .12);
}
[data-theme="royal"] {
  --bg: #f2eefa; --surface: #ffffff; --surface2: #e8e0f6; --text: #231546; --muted: #6f6390; --border: #d9cfee;
  --primary: #6a3fc4; --primary-text: #fff; --accent: #d49a1a; --good: #2f9a68; --warn: #d89a00; --bad: #cc3f56; --info: #4a80c4;
  --side-bg: #231346; --side-text: #d9ccf4; --side-active: #6a3fc4; --shadow: 0 2px 10px rgba(35, 19, 70, .12);
}
[data-theme="contrast"] {
  --bg: #000000; --surface: #000000; --surface2: #111111; --text: #ffffff; --muted: #e0e0e0; --border: #ffffff;
  --primary: #ffe600; --primary-text: #000000; --accent: #00e5ff; --good: #00ff7f; --warn: #ffd000; --bad: #ff5c5c; --info: #66b3ff;
  --side-bg: #000000; --side-text: #ffffff; --side-active: #ffe600; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: "Segoe UI", system-ui, -apple-system, "Noto Sans", "Noto Sans Arabic", "Noto Sans SC", "Noto Sans Devanagari", Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; }
a { color: var(--primary); }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; gap: .45rem; padding: .5rem .95rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; font-weight: 600; transition: filter .15s, transform .05s; }
.btn:hover { filter: brightness(.96); } .btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.btn.danger { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn.sm { padding: .25rem .55rem; font-size: .85rem; }
.btn.icon { padding: .4rem .6rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .85rem; }
.field label { font-size: .85rem; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea, .tb-input, .tb-select, .sel {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .5rem .65rem; width: 100%; }
.field textarea { min-height: 76px; resize: vertical; }
.tb-input, .tb-select, .sel { width: auto; }
.sel { padding: .3rem .45rem; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1rem; }
.form-grid .full { grid-column: 1 / -1; }
.err { color: var(--bad); font-weight: 600; min-height: 1.4em; margin: .2rem 0; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 1.5rem;
  background: radial-gradient(circle at 20% 10%, color-mix(in srgb, var(--primary) 22%, transparent), transparent 55%),
              radial-gradient(circle at 85% 90%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 55%), var(--bg); }
.login-top { position: fixed; top: 12px; inset-inline-end: 12px; display: flex; gap: .5rem; }
.login-card { width: min(430px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 2rem 1.75rem; box-shadow: var(--shadow); text-align: center; }
.logo { width: 64px; height: 64px; border-radius: 16px; display: grid; place-items: center; margin: 0 auto .75rem;
  background: linear-gradient(135deg, var(--primary), var(--accent)); color: var(--primary-text); font-size: 1.8rem; }
.login-card h1 { font-size: 1.2rem; margin: 0 0 .25rem; } .login-card p.sub { color: var(--muted); margin: 0 0 1.25rem; }
.login-card form { text-align: start; }
.credit { font-weight: 700; text-align: center; color: var(--primary); }
.login-credit { margin-top: 1.25rem; padding: .75rem 1rem; border-radius: 12px; background: var(--surface); border: 1px dashed var(--primary); max-width: 560px; text-align: center; }
.hint { background: var(--surface2); border-radius: 8px; padding: .5rem .7rem; font-size: .85rem; color: var(--muted); margin-bottom: 1rem; }

/* ---------- shell ---------- */
.app { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar { background: var(--side-bg); color: var(--side-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; gap: .7rem; align-items: center; padding: 1.1rem 1rem; border-bottom: 1px solid rgba(255, 255, 255, .12); }
.brand .logo { margin: 0; width: 40px; height: 40px; font-size: 1.15rem; flex: none; }
.brand b { display: block; font-size: .95rem; line-height: 1.2; color: #fff; } .brand small { opacity: .75; font-size: .75rem; }
.nav { display: flex; flex-direction: column; gap: 2px; padding: .75rem .6rem; flex: 1; }
.nav a { display: flex; gap: .7rem; align-items: center; padding: .6rem .8rem; border-radius: 8px; color: inherit; text-decoration: none; font-weight: 600; }
.nav a i { width: 1.2rem; text-align: center; }
.nav a:hover { background: rgba(255, 255, 255, .1); }
.nav a.active { background: var(--side-active); color: var(--primary-text); }
[data-theme="contrast"] .nav a.active { color: #000; }
.side-foot { padding: .8rem 1rem; font-size: .75rem; opacity: .8; border-top: 1px solid rgba(255, 255, 255, .12); text-align: center; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: .6rem; padding: .6rem 1.1rem; flex-wrap: wrap; }
.topbar h2 { margin: 0; font-size: 1.1rem; flex: 1; min-width: 140px; }
.menu-btn { display: none; }
.userchip { display: flex; align-items: center; gap: .5rem; padding: .25rem .7rem; border-radius: 99px; background: var(--surface2); font-weight: 600; font-size: .9rem; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--primary); color: var(--primary-text); display: grid; place-items: center; font-size: .8rem; }
#view { padding: 1.2rem; flex: 1; }
.footer { text-align: center; padding: .9rem; color: var(--muted); font-size: .85rem; border-top: 1px solid var(--border); }

/* ---------- cards / dashboard ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 1rem 1.1rem; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 .7rem; font-size: 1rem; }
.hero { text-align: center; padding: 1.2rem 1rem; margin-bottom: 1.1rem; background: linear-gradient(135deg, color-mix(in srgb, var(--primary) 14%, var(--surface)), color-mix(in srgb, var(--accent) 14%, var(--surface))); }
.hero h2 { margin: 0 0 .25rem; font-size: 1.35rem; } .hero p { margin: 0 0 .7rem; color: var(--muted); }
.hero .credit { font-size: 1.1rem; display: inline-block; padding: .5rem 1.1rem; border-radius: 99px; border: 2px solid var(--primary); background: var(--surface); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .9rem; margin-bottom: 1.1rem; }
.kpi { display: flex; flex-direction: column; gap: .15rem; } .kpi .v { font-size: 1.9rem; font-weight: 800; line-height: 1.1; } .kpi .l { color: var(--muted); font-size: .85rem; }
.kpi.score { align-items: center; text-align: center; }
.ring { --p: 0; width: 104px; height: 104px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--primary) calc(var(--p) * 1%), var(--surface2) 0); }
.ring span { width: 80px; height: 80px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; font-size: 1.5rem; font-weight: 800; }
.grid2 { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: .9rem; margin-bottom: .9rem; }
.grid2.even { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.chart-box { position: relative; height: 300px; } .chart-box.tall { height: 430px; }
.list { list-style: none; margin: 0; padding: 0; } .list li { display: flex; gap: .6rem; align-items: center; justify-content: space-between; padding: .45rem 0; border-bottom: 1px solid var(--border); font-size: .9rem; }
.list li:last-child { border-bottom: 0; } .muted { color: var(--muted); } .small { font-size: .82rem; }
.empty { text-align: center; color: var(--muted); padding: 1.2rem .5rem; }

/* ---------- badges / tables ---------- */
.badge { display: inline-block; padding: .1rem .55rem; border-radius: 99px; font-size: .75rem; font-weight: 700; white-space: nowrap;
  background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.badge.good { background: color-mix(in srgb, var(--good) 20%, transparent); color: var(--good); border-color: var(--good); }
.badge.warn { background: color-mix(in srgb, var(--warn) 22%, transparent); color: var(--warn); border-color: var(--warn); }
.badge.bad { background: color-mix(in srgb, var(--bad) 18%, transparent); color: var(--bad); border-color: var(--bad); }
.badge.info { background: color-mix(in srgb, var(--info) 18%, transparent); color: var(--info); border-color: var(--info); }
.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: .9rem; }
.toolbar .grow { flex: 1; min-width: 160px; }
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th, .tbl td { padding: .55rem .6rem; text-align: start; border-bottom: 1px solid var(--border); vertical-align: top; }
.tbl th { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
.tbl tr:hover td { background: var(--surface2); }
.tbl .acts { white-space: nowrap; text-align: end; }
.clip { max-width: 320px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.overdue { color: var(--bad); font-weight: 700; }

/* ---------- checklist ---------- */
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: .45rem .8rem; cursor: pointer; font-weight: 600; }
.seg button.on { background: var(--primary); color: var(--primary-text); }
details.grp { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; margin-bottom: .7rem; overflow: hidden; }
details.grp > summary { list-style: none; cursor: pointer; display: flex; gap: .8rem; align-items: center; padding: .75rem 1rem; font-weight: 700; background: var(--surface2); }
details.grp > summary::-webkit-details-marker { display: none; }
details.grp > summary .pbar { flex: 0 0 140px; }
.pbar { height: 8px; border-radius: 99px; background: var(--border); overflow: hidden; } .pbar i { display: block; height: 100%; background: var(--good); }
.ck-row { display: grid; grid-template-columns: 70px 1fr 170px auto; gap: .7rem; align-items: center; padding: .6rem 1rem; border-top: 1px solid var(--border); border-inline-start: 4px solid transparent; }
.ck-row.im { border-inline-start-color: var(--good); } .ck-row.ip { border-inline-start-color: var(--warn); } .ck-row.ns { border-inline-start-color: var(--bad); } .ck-row.na { border-inline-start-color: var(--muted); }
.ck-id { font-weight: 800; color: var(--primary); } .ck-title b { display: block; } .ck-title small { color: var(--muted); }

/* ---------- modal / toast ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); display: grid; place-items: center; z-index: 100; padding: 1rem; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; width: min(640px, 100%); max-height: 92vh; display: flex; flex-direction: column; box-shadow: 0 10px 40px rgba(0, 0, 0, .35); }
.modal.wide { width: min(860px, 100%); }
.modal header { display: flex; justify-content: space-between; align-items: center; padding: .85rem 1.1rem; border-bottom: 1px solid var(--border); font-weight: 700; }
.modal .body { padding: 1rem 1.1rem; overflow-y: auto; } .modal footer { padding: .8rem 1.1rem; border-top: 1px solid var(--border); display: flex; gap: .5rem; justify-content: flex-end; }
#toasts { position: fixed; bottom: 16px; inset-inline-start: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: .4rem; align-items: center; }
.toast { background: var(--text); color: var(--bg); padding: .55rem 1rem; border-radius: 8px; box-shadow: var(--shadow); font-weight: 600; }
.toast.bad { background: var(--bad); color: #fff; }

/* ---------- permissions matrix ---------- */
.pm { width: 100%; border-collapse: collapse; } .pm th, .pm td { padding: .4rem .5rem; border-bottom: 1px solid var(--border); text-align: center; } .pm td:first-child, .pm th:first-child { text-align: start; }
.pm input { width: 18px; height: 18px; }
.cards3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: .9rem; } .cards3 .card p { color: var(--muted); font-size: .9rem; }
.result { background: var(--surface2); border-radius: 8px; padding: .6rem .8rem; margin-top: .7rem; font-size: .88rem; white-space: pre-wrap; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset-block: 0; inset-inline-start: 0; width: 260px; z-index: 60; transform: translateX(-105%); transition: transform .2s; }
  [dir="rtl"] .sidebar { transform: translateX(105%); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 50; }
  .menu-btn { display: inline-flex; }
  .grid2, .grid2.even { grid-template-columns: 1fr; }
  .ck-row { grid-template-columns: 56px 1fr; } .ck-row .ck-st, .ck-row .ck-act { grid-column: 2; }
  .form-grid { grid-template-columns: 1fr; }
  details.grp > summary .pbar { flex-basis: 70px; }
  .userchip span.nm { display: none; }
}
