/* UAEICP Employee Intelligence Workspace
   Palette: UAE Federal Government design system (as used by icp.gov.ae)
   aegold #B68A35 · charcoal #232323 · white · flag accents */
:root {
  --gold: #B68A35;
  --gold-dark: #92722A;
  --gold-deep: #7A5F22;
  --gold-light: #D4B06A;
  --gold-tint: #F6EFE0;
  --black: #232323;
  --black-soft: #3A3A38;
  --ink: #2B2A28;
  --muted: #6E6A62;
  --line: #E5E1D8;
  --bg: #F7F6F3;
  --card: #FFFFFF;
  --green: #007A3D;
  --green-tint: #E4F1EA;
  --red: #C3002F;
  --red-tint: #FBE9ED;
  --amber: #9A6A00;
  --amber-tint: #FBF3DC;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(35, 35, 35, .07), 0 4px 18px rgba(35, 35, 35, .06);
  --font: 'IBM Plex Sans', 'IBM Plex Sans Arabic', system-ui, sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font); background: var(--bg); color: var(--ink);
  font-size: 15px; overflow-x: hidden;
}
[dir="rtl"] body, [dir="rtl"] { font-family: 'IBM Plex Sans Arabic', 'IBM Plex Sans', system-ui, sans-serif; }

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }
a { color: var(--gold-dark); }

/* Global overflow protection */
p, li, td, th, h1, h2, h3, h4, div { overflow-wrap: break-word; word-break: break-word; }
.grow { min-width: 0; }

/* UAE flag accent strip */
.flagbar {
  height: 4px; width: 100%;
  background: linear-gradient(90deg,
    var(--red) 0 10%, var(--green) 10% 40%, #fff 40% 70%, var(--black) 70% 100%);
}
[dir="rtl"] .flagbar {
  background: linear-gradient(270deg,
    var(--red) 0 10%, var(--green) 10% 40%, #fff 40% 70%, var(--black) 70% 100%);
}

/* ---------- shared ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; border-radius: 8px; padding: 10px 18px;
  font-size: 14px; font-weight: 600; transition: .15s; white-space: nowrap;
}
.btn-primary { background: var(--gold); color: #fff; }
.btn-primary:hover { background: var(--gold-dark); }
.btn-dark { background: var(--black); color: #fff; }
.btn-dark:hover { background: var(--black-soft); }
.btn-ghost { background: transparent; color: var(--gold-deep); border: 1px solid var(--line); }
.btn-ghost:hover { background: var(--gold-tint); border-color: var(--gold-light); }
.btn-danger { background: transparent; color: var(--red); border: 1px solid #f2cdd6; }
.btn-danger:hover { background: var(--red-tint); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 6px; }

.input, textarea.input, select.input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; color: var(--ink); outline: none; transition: .15s;
}
.input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(182, 138, 53, .15); }
label.f { display: block; font-size: 13px; font-weight: 700; color: var(--black); margin: 16px 0 5px; }
.help { font-size: 12.5px; color: var(--muted); line-height: 1.5; margin-top: 4px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 99px;
  font-size: 11.5px; font-weight: 700; letter-spacing: .3px; white-space: nowrap;
}
.badge.high { background: var(--green-tint); color: var(--green); }
.badge.medium { background: var(--amber-tint); color: var(--amber); }
.badge.low { background: var(--red-tint); color: var(--red); }
.badge.spec { background: #EFE7FA; color: #5B3E96; }
.badge.mode { background: var(--gold-tint); color: var(--gold-deep); }
.badge.gold { background: var(--gold-tint); color: var(--gold-deep); border: 1px solid var(--gold-light); }

.spinner {
  width: 18px; height: 18px; border: 2.5px solid rgba(255,255,255,.35);
  border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; flex: none;
}
.spinner.dark { border-color: rgba(146,114,42,.25); border-top-color: var(--gold-dark); }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--black); color: #fff; padding: 12px 22px; border-radius: 10px;
  box-shadow: var(--shadow); z-index: 999; font-size: 14px; max-width: 90vw;
}
.toast.err { background: var(--red); }

.logo-img { display: block; object-fit: contain; }

/* ---------- login ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(165deg, #1C1C1B 0%, var(--black) 50%, #35301F 100%);
  position: relative; overflow: hidden; padding: 20px;
}
.login-wrap::before {
  content: ''; position: absolute; inset: 0;
  background:
    radial-gradient(700px 340px at 85% 12%, rgba(182,138,53,.22), transparent 60%),
    radial-gradient(520px 420px at 8% 92%, rgba(182,138,53,.10), transparent 60%);
}
.login-card {
  position: relative; width: 440px; max-width: 94vw; background: #fff;
  border-radius: 16px; padding: 0 0 34px; box-shadow: 0 24px 80px rgba(0,0,0,.5);
  overflow: hidden;
}
.login-card .flagbar { border-radius: 16px 16px 0 0; }
.login-card .inner { padding: 32px 36px 0; }
.login-card .logo-img { width: 200px; max-width: 70%; height: 92px; margin: 0 auto 14px; }
.login-card h1 { font-size: 18px; text-align: center; color: var(--black); line-height: 1.4; }
.login-card .authority { text-align: center; font-size: 12px; color: var(--muted); margin: 8px 0 4px; line-height: 1.5; }
.login-card .internal {
  text-align: center; font-size: 11.5px; color: var(--amber); font-weight: 600;
  background: var(--amber-tint); border-radius: 6px; padding: 6px 10px; margin: 14px 0 4px;
}
.login-card .hint { font-size: 12px; color: var(--muted); text-align: center; margin-top: 16px; line-height: 1.5; }
.login-err { color: var(--red); font-size: 13px; margin-top: 10px; text-align: center; }
.lang-float { position: absolute; top: 20px; inset-inline-end: 24px; z-index: 2; width: auto; }
.lang-float select { width: auto; }

/* ---------- app shell ---------- */
.shell { display: flex; flex-direction: column; min-height: 100vh; }
.topbar {
  background: var(--black); color: #fff;
  display: flex; align-items: center; gap: 14px; padding: 10px 22px; min-height: 62px;
  border-bottom: 3px solid var(--gold); position: sticky; top: 0; z-index: 50; flex-wrap: wrap;
}
.topbar .logo-img { height: 40px; max-width: 190px; flex: none; }
.topbar .titles { min-width: 0; }
.topbar .title { font-weight: 600; font-size: 14.5px; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .subtitle { font-size: 10.5px; opacity: .7; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .grow { flex: 1; }
.topbar select {
  background: rgba(255,255,255,.1); color: #fff; border: 1px solid rgba(255,255,255,.28);
  border-radius: 7px; padding: 6px 10px; max-width: 200px;
}
.topbar select option { color: var(--ink); }
.topbar .user { font-size: 13px; opacity: .9; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .btn-ghost { color: #fff; border-color: rgba(255,255,255,.32); }
.topbar .btn-ghost:hover { background: rgba(255,255,255,.12); border-color: var(--gold-light); color: #fff; }
@media (max-width: 820px) { .topbar .titles { display: none; } }
.main { flex: 1; padding: 28px 22px; max-width: 1200px; width: 100%; margin: 0 auto; }

/* ---------- dashboard ---------- */
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h2 { font-size: 22px; color: var(--black); }
.page-head .grow { flex: 1; }
.ws-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 18px; }
.ws-card { padding: 20px; display: flex; flex-direction: column; gap: 10px; transition: .15s; border-top: 3px solid var(--gold); }
.ws-card:hover { transform: translateY(-2px); box-shadow: 0 8px 28px rgba(35,35,35,.14); }
.ws-card h3 { font-size: 16px; color: var(--black); }
.ws-card .meta { font-size: 12px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; }
.ws-card .brief { font-size: 13px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ws-card .row { display: flex; gap: 8px; margin-top: 6px; flex-wrap: wrap; }

/* ---------- modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(20,20,18,.6); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal { background: #fff; border-radius: 14px; width: 560px; max-width: 100%; max-height: 92vh; overflow: auto; padding: 28px; }
.modal h3 { color: var(--black); margin-bottom: 4px; font-size: 19px; }
.modal .sub { font-size: 13px; color: var(--muted); line-height: 1.5; margin-bottom: 8px; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 24px; }

/* choice cards (mode / language pickers) */
.choices { display: grid; gap: 10px; margin-top: 6px; }
.choices.two { grid-template-columns: 1fr 1fr; }
@media (max-width: 560px) { .choices.two { grid-template-columns: 1fr; } }
.choice-card {
  display: block; border: 1.5px solid var(--line); border-radius: 10px;
  padding: 13px 14px; cursor: pointer; transition: .15s; background: #fff;
}
.choice-card:hover { border-color: var(--gold-light); }
.choice-card:has(input:checked) { border-color: var(--gold); background: var(--gold-tint); box-shadow: 0 0 0 3px rgba(182,138,53,.12); }
.choice-card input { accent-color: var(--gold-dark); margin-inline-end: 8px; }
.choice-card .cc-title { font-weight: 700; font-size: 13.5px; color: var(--black); display: inline; }
.choice-card .cc-desc { font-size: 12px; color: var(--muted); line-height: 1.5; margin-top: 5px; }

/* ---------- workspace ---------- */
.ws-head { margin-bottom: 18px; }
.ws-head h2 { font-size: 21px; color: var(--black); }
.ws-head .meta { display: flex; gap: 10px; align-items: center; margin-top: 8px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); margin-bottom: 20px; overflow-x: auto; }
.tab {
  padding: 10px 18px; border: none; background: none; font-size: 14px; font-weight: 600;
  color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -2px; white-space: nowrap;
}
.tab.active { color: var(--gold-deep); border-bottom-color: var(--gold); }
.panel { animation: fade .2s; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

.file-row {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  border-bottom: 1px solid var(--line); font-size: 14px; flex-wrap: wrap;
}
.file-row:last-child { border-bottom: none; }
.file-ico {
  width: 36px; height: 36px; border-radius: 8px; background: var(--gold-tint);
  color: var(--gold-deep); display: flex; align-items: center; justify-content: center;
  font-size: 10.5px; font-weight: 700; flex: none;
}
.file-row .grow { flex: 1; min-width: 140px; }
.file-row .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row .sub { font-size: 12px; color: var(--muted); }
.dropzone {
  border: 2px dashed var(--gold-light); border-radius: var(--radius); padding: 34px 20px;
  text-align: center; color: var(--muted); background: #fff; transition: .15s; cursor: pointer;
}
.dropzone.drag { border-color: var(--gold); background: var(--gold-tint); }
.dropzone strong { color: var(--gold-deep); }

/* analysis */
.a-section { padding: 18px 20px; margin-bottom: 14px; }
.a-section h4 {
  font-size: 13px; text-transform: uppercase; letter-spacing: .8px;
  color: var(--gold-deep); margin-bottom: 10px; display: flex; align-items: center; gap: 8px;
}
.a-section h4::before { content: ''; width: 8px; height: 8px; border-radius: 2px; background: var(--gold); flex: none; }
.a-section ul { padding-inline-start: 20px; display: grid; gap: 7px; font-size: 14px; }
.a-section .item { display: flex; gap: 10px; align-items: flex-start; padding: 7px 0; border-bottom: 1px dashed var(--line); font-size: 14px; flex-wrap: wrap; }
.a-section .item:last-child { border-bottom: none; }
.a-section .item .grow { flex: 1; min-width: 200px; }
.cite {
  font-size: 12.5px; color: var(--gold-deep); background: var(--gold-tint);
  border-radius: 5px; padding: 1px 7px; overflow-wrap: anywhere; display: inline;
}
.exec { font-size: 15px; line-height: 1.65; }
.disclaimer-bar {
  background: var(--amber-tint); color: var(--amber); border: 1px solid #ecdcb0;
  font-size: 12.5px; padding: 9px 14px; border-radius: 8px; margin-bottom: 16px; font-weight: 600;
}
.demo-bar { background: #EFE7FA; color: #5B3E96; border: 1px solid #ddd0f2; }

/* chat */
.chat-box { display: flex; flex-direction: column; height: 62vh; min-height: 380px; }
.chat-log { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.msg {
  max-width: min(82%, 720px); padding: 12px 16px; border-radius: 14px;
  font-size: 14px; line-height: 1.6; overflow-wrap: anywhere;
}
.msg.user { align-self: flex-end; background: var(--black); color: #fff; border-end-end-radius: 4px; }
[dir="rtl"] .msg.user { align-self: flex-start; }
.msg.assistant { align-self: flex-start; background: #fff; border: 1px solid var(--line); border-end-start-radius: 4px; }
[dir="rtl"] .msg.assistant { align-self: flex-end; }
.msg .who { font-size: 11px; opacity: .65; margin-bottom: 5px; font-weight: 700; }
.msg :is(h1,h2,h3,h4) { font-size: 14px; margin: 10px 0 4px; color: var(--gold-deep); }
.msg.user :is(h1,h2,h3,h4) { color: var(--gold-light); }
.msg ul, .msg ol { padding-inline-start: 20px; margin: 6px 0; }
.msg p { margin: 6px 0; }
.msg code { background: rgba(0,0,0,.06); padding: 1px 5px; border-radius: 4px; font-size: 13px; overflow-wrap: anywhere; }
.msg.user code { background: rgba(255,255,255,.15); }
.msg table { display: block; overflow-x: auto; max-width: 100%; border-collapse: collapse; margin: 8px 0; }
.msg td, .msg th { border: 1px solid var(--line); padding: 5px 9px; font-size: 13px; }
.chat-input { display: flex; gap: 10px; padding: 14px; border-top: 1px solid var(--line); background: #fff; border-radius: 0 0 var(--radius) var(--radius); }
.chat-input textarea { flex: 1; resize: none; height: 52px; min-width: 0; }

/* studio */
.studio-grid { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 20px; }
@media (max-width: 860px) { .studio-grid { grid-template-columns: 1fr; } }
.out-row { display: flex; align-items: center; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--line); font-size: 14px; flex-wrap: wrap; }
.out-row:last-child { border-bottom: none; }
.out-row .grow { min-width: 150px; }
.output-view { padding: 22px; white-space: pre-wrap; font-size: 14px; line-height: 1.7; max-height: 65vh; overflow: auto; overflow-wrap: anywhere; }
.output-view :is(h1,h2,h3) { color: var(--black); margin: 14px 0 6px; }
.output-view table { border-collapse: collapse; margin: 10px 0; display: block; overflow-x: auto; max-width: 100%; }
.output-view td, .output-view th { border: 1px solid var(--line); padding: 6px 10px; font-size: 13px; }

/* notes & admin */
.note-row { padding: 13px 16px; border-bottom: 1px solid var(--line); font-size: 14px; display: flex; gap: 12px; align-items: flex-start; }
.note-row:last-child { border-bottom: none; }
.note-row .when { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
table.admin { width: 100%; border-collapse: collapse; font-size: 14px; }
table.admin th { text-align: start; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); padding: 10px 14px; border-bottom: 2px solid var(--line); white-space: nowrap; }
table.admin td { padding: 11px 14px; border-bottom: 1px solid var(--line); }
.empty-state { text-align: center; color: var(--muted); padding: 48px 20px; font-size: 14px; line-height: 1.7; }
.empty-state .big { font-size: 34px; margin-bottom: 10px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #CFC9BC; border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }
