:root {
  --ink: #0E1A2B;
  --ink-2: #3C4757;
  --muted: #5B6676;
  --line: #E3E6EB;
  --line-soft: #EEF0F3;
  --bg: #F5F6F8;
  --surface: #FFFFFF;
  --accent: #1F4FD8;
  --accent-dark: #163BA6;
  --accent-soft: #E8EEFF;
  --on-dark: #C7CFDB;
  --on-dark-accent: #9DB4FF;
  --amber-bg: #FEF3E2; --amber-fg: #93370D;
  --green-bg: #ECFDF3; --green-fg: #05603A;
  --red-bg: #FEE4E2;   --red-fg: #912018;
  --grey-bg: #EEF0F3;  --grey-fg: #3C4757;
  --blue-bg: #E8EEFF;  --blue-fg: #163BA6;
  --radius: 14px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
}

h1, h2, h3 {
  margin: 0;
  font-family: Manrope, Inter, system-ui, sans-serif;
  letter-spacing: -0.02em;
}
h1 { font-size: 30px; font-weight: 700; }
h2 { font-size: 18px; font-weight: 700; }
p { margin: 0; }
a { color: var(--accent); }
a:hover { color: var(--accent-dark); }
:focus-visible { outline: 3px solid var(--on-dark-accent); outline-offset: 2px; }

.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;
}

/* ---------- Brand ---------- */
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  font-family: Manrope, sans-serif; font-weight: 800; font-size: 20px;
  letter-spacing: -0.02em; color: inherit; text-decoration: none;
}
.brand:hover { color: inherit; }
.brand span { color: var(--accent); }
.dark .brand span, .auth-brand .brand span { color: var(--on-dark-accent); }

/* ---------- Buttons & fields ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px; border-radius: 10px;
  border: 1px solid transparent; font: inherit; font-weight: 600;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-dark); color: #fff; }
.btn-secondary { background: var(--surface); border-color: #D5DAE1; color: var(--ink); }
.btn-secondary:hover:not(:disabled) { background: var(--bg); color: var(--ink); }
.btn-ghost { background: transparent; color: var(--accent); padding: 0 10px; }
.btn-ghost:hover:not(:disabled) { background: var(--accent-soft); }
.btn-danger { background: transparent; color: var(--red-fg); padding: 0 10px; }
.btn-danger:hover:not(:disabled) { background: var(--red-bg); }
.btn-sm { min-height: 38px; padding: 0 12px; font-size: 14px; }
.btn-block { width: 100%; }
.dark .btn-ghost { color: #fff; }
.dark .btn-ghost:hover { background: #1F2E44; }
label.btn:focus-within { outline: 3px solid var(--on-dark-accent); outline-offset: 2px; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .label { font-size: 14px; font-weight: 600; }
input[type="text"], input[type="email"], input[type="date"], input[type="search"],
select, textarea {
  width: 100%; min-height: 44px; padding: 0 12px;
  border: 1px solid #D5DAE1; border-radius: 10px;
  font: inherit; color: var(--ink); background: var(--surface);
}
textarea { padding: 10px 12px; min-height: 72px; resize: vertical; }
input::placeholder, textarea::placeholder { color: #7A8494; }
.code-input { font-size: 22px; letter-spacing: 0.3em; text-align: center; }

.msg { font-size: 14px; min-height: 1.5em; color: var(--muted); }
.msg.error { color: var(--red-fg); }
.msg.ok { color: var(--green-fg); }

/* ---------- Sign-in page ---------- */
.auth { min-height: 100vh; display: flex; flex-wrap: wrap; }
.auth-brand {
  flex: 1 1 480px; min-width: 0; background: var(--ink); color: #fff;
  padding: 48px 56px; display: flex; flex-direction: column;
  justify-content: space-between; gap: 40px;
}
.auth-brand .eyebrow {
  font-size: 13px; font-weight: 600; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--on-dark-accent);
}
.auth-brand h1 { font-size: 44px; line-height: 1.1; max-width: 520px; }
.auth-brand .lead { font-size: 17px; line-height: 1.6; color: var(--on-dark); max-width: 520px; }
.auth-brand ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; color: #E6EAF0; }
.auth-brand li { display: flex; gap: 10px; align-items: center; }
.auth-brand .foot { font-size: 13px; color: #9AA5B5; }
.auth-panel {
  flex: 1 1 440px; min-width: 0; display: flex; align-items: center;
  justify-content: center; padding: 48px 24px;
}
.auth-card { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 20px; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; }
.divider { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.hint { font-size: 13px; color: var(--muted); }
.warning {
  background: var(--amber-bg); color: var(--amber-fg); border-radius: 10px;
  padding: 12px 14px; font-size: 14px;
}

@media (max-width: 600px) {
  .auth-brand { padding: 32px 20px; }
  .auth-brand h1 { font-size: 32px; }
  .auth-brand ul { display: none; }
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 12px 20px; padding: 12px 24px; background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topbar.dark { background: var(--ink); color: #fff; border-bottom: 0; }
.topbar-left, .topbar-right { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.topbar .who { font-size: 14px; color: var(--muted); }
.topbar.dark .who { color: var(--on-dark); }
.tag {
  padding: 4px 10px; border-radius: 999px; background: #1F2E44;
  font-size: 12px; font-weight: 600; color: var(--on-dark);
}
.company-select { width: auto; min-width: 220px; min-height: 40px; font-weight: 600; background: var(--bg); }

/* ---------- Layout ---------- */
.page {
  max-width: 1120px; margin: 0 auto; padding: 28px 24px 64px;
  display: flex; flex-direction: column; gap: 24px;
}
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 12px; }
.page-head .sub { color: var(--muted); margin-top: 4px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; display: flex; flex-direction: column; gap: 4px;
}
.stat .label { font-size: 13px; color: var(--muted); }
.stat .value { font-family: Manrope, sans-serif; font-size: 32px; font-weight: 700; letter-spacing: -0.02em; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px; display: flex; flex-direction: column; gap: 16px; min-width: 0;
}
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; }
.card-head .sub { font-size: 14px; color: var(--muted); }

.list { display: flex; flex-direction: column; }
.item {
  display: flex; flex-wrap: wrap; gap: 12px 20px; justify-content: space-between;
  align-items: flex-start; padding: 16px 0; border-top: 1px solid var(--line-soft);
}
.item:first-child { border-top: 0; padding-top: 4px; }
.item-main { flex: 1 1 320px; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.item-title { font-weight: 600; font-size: 15px; }
.item-side { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.meta { font-size: 13px; color: var(--muted); }
.overdue { color: var(--red-fg); font-weight: 600; }
.desc { font-size: 14px; color: var(--ink-2); white-space: pre-line; }
.note {
  background: var(--amber-bg); color: var(--amber-fg); border-radius: 8px;
  padding: 8px 12px; font-size: 14px; white-space: pre-line;
}
.empty { color: var(--muted); padding: 8px 0; }

.pill {
  display: inline-flex; align-items: center; padding: 4px 10px; border-radius: 999px;
  font-size: 13px; font-weight: 600; white-space: nowrap;
}
.pill-amber { background: var(--amber-bg); color: var(--amber-fg); }
.pill-green { background: var(--green-bg); color: var(--green-fg); }
.pill-red { background: var(--red-bg); color: var(--red-fg); }
.pill-grey { background: var(--grey-bg); color: var(--grey-fg); }
.pill-blue { background: var(--blue-bg); color: var(--blue-fg); }

.files { display: flex; flex-wrap: wrap; gap: 8px; }
.file {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  font-size: 13px; padding: 5px 10px; border: 1px solid var(--line);
  border-radius: 8px; color: var(--ink); text-decoration: none; background: var(--bg);
}
.file:hover { border-color: var(--accent); color: var(--accent-dark); }
.file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.state-box {
  max-width: 560px; margin: 48px auto; text-align: center;
  display: flex; flex-direction: column; gap: 12px; align-items: center;
}

/* ---------- Team (admin) page ---------- */
.admin-layout {
  max-width: 1280px; margin: 0 auto; padding: 24px 24px 64px;
  display: flex; flex-wrap: wrap; gap: 24px; align-items: flex-start;
}
.admin-side { flex: 1 1 260px; max-width: 100%; display: flex; flex-direction: column; gap: 16px; }
.admin-main { flex: 999 1 600px; min-width: 0; display: flex; flex-direction: column; gap: 24px; }
.company-list { display: flex; flex-direction: column; gap: 2px; max-height: 60vh; overflow-y: auto; }
.company-btn {
  display: block; width: 100%; text-align: left; min-height: 44px; padding: 8px 12px;
  border: 0; border-radius: 8px; background: transparent; font: inherit;
  font-size: 14px; font-weight: 500; color: var(--ink-2); cursor: pointer;
}
.company-btn:hover { background: var(--bg); }
.company-btn[aria-current="true"] { background: var(--accent-soft); color: var(--accent-dark); font-weight: 600; }
.form-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px; align-items: end;
}
.form-grid .wide { grid-column: 1 / -1; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.inline-form .field { flex: 1 1 200px; }
.edit-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; width: 100%; }
.edit-row select { width: auto; min-width: 170px; }
.edit-row input { flex: 1 1 220px; width: auto; }
.member-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line-soft); }
.member-row:first-child { border-top: 0; }
details.add { border: 1px dashed #C9CFD8; border-radius: 10px; padding: 12px 14px; }
details.add summary { cursor: pointer; font-weight: 600; color: var(--accent); }
details.add[open] summary { margin-bottom: 14px; }
.brand .brand-name { color: inherit; }
.brand .brand-name span { color: var(--accent); }
.dark .brand .brand-name span, .auth-brand .brand .brand-name span { color: var(--on-dark-accent); }
.item .msg:empty, .card > .msg:empty, .admin-side .msg:empty { display: none; }
