:root {
  --paper: #f3efe6;
  --paper-2: #eae4d6;
  --ink: #1f1b16;
  --ink-soft: #5c5348;
  --line: #d4cbb8;
  --accent: #0e4b56;
  --accent-2: #1a6a78;
  --accent-soft: #d7ecec;
  --paid: #2f6b4f;
  --paid-bg: #dceee4;
  --refused: #8b3a32;
  --refused-bg: #f3ddd9;
  --warn: #9a6b1f;
  --warn-bg: #f4e6c4;
  --white: #fffcf7;
  --shadow: 0 18px 50px rgba(31, 27, 22, 0.12);
  --sidebar: 240px;
  --font: "IBM Plex Sans", "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
}

button, input, select, textarea { font-family: inherit; font-size: 14px; }
button { cursor: pointer; }

.hidden { display: none !important; }

/* Login */
.login-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 32px;
  background:
    radial-gradient(900px 400px at 10% -10%, #d7ecec 0%, transparent 50%),
    radial-gradient(700px 400px at 110% 20%, #f4e6c4 0%, transparent 45%),
    var(--paper);
}
.login-card {
  width: min(420px, 100%);
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 32px 28px 24px;
  box-shadow: var(--shadow);
}
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.login-card h1 { margin: 16px 0 4px; font-size: 26px; font-weight: 600; }
.login-card .lead { margin: 0 0 22px; color: var(--ink-soft); line-height: 1.45; }
.login-card label { display: block; font-size: 12px; font-weight: 600; margin: 0 0 6px; }
.login-card input {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  margin-bottom: 12px;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-weight: 600;
}
.btn-primary { background: var(--accent); color: #fff; }
.login-card .btn-primary { width: 100%; height: 44px; margin-top: 6px; }
.btn-primary:hover { background: var(--accent-2); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { background: var(--paper-2); }
.btn-danger { background: var(--refused); color: #fff; }
.btn-sm { height: 32px; padding: 0 10px; font-size: 13px; width: auto; margin-top: 0; }
.drawer-actions .btn-primary, .drawer-actions .btn-ghost, .drawer-actions .btn-danger {
  width: auto;
  height: 40px;
  margin-top: 0;
}
.demo-box {
  margin-top: 18px;
  padding: 12px;
  background: var(--paper);
  border-radius: 10px;
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.55;
}
.demo-box b { color: var(--ink); }
.err { color: var(--refused); font-size: 13px; min-height: 18px; margin: 0 0 8px; }

/* App shell */
.app {
  display: grid;
  grid-template-columns: var(--sidebar) 1fr;
  min-height: 100%;
}
.sidebar {
  background: #12343b;
  color: #e7f2f3;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sidebar .logo {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 4px 8px 18px;
}
.sidebar .logo strong { display: block; font-size: 15px; }
.sidebar .logo span { display: block; font-size: 11px; opacity: 0.7; }
.nav-btn {
  text-align: left;
  background: transparent;
  color: inherit;
  border: 0;
  border-radius: 10px;
  padding: 10px 12px;
  opacity: 0.85;
}
.nav-btn:hover, .nav-btn.active { background: rgba(255,255,255,0.1); opacity: 1; }
.sidebar .spacer { flex: 1; }
.who {
  padding: 12px;
  background: rgba(0,0,0,0.18);
  border-radius: 12px;
  font-size: 13px;
}
.who small { display: block; opacity: 0.7; margin-top: 2px; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,252,247,0.8);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar h2 { margin: 0; font-size: 20px; font-weight: 600; flex: 1; }
.live-presence {
  font-size: 13px;
  color: var(--ink-soft);
  background: var(--accent-soft);
  border: 1px solid #c5e0e0;
  border-radius: 999px;
  padding: 6px 12px;
  white-space: nowrap;
}
.live-presence b { color: var(--accent); }
.presence-people {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 16px;
}
.presence-people span {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
}
.banner {
  margin: 16px 22px 0;
  padding: 10px 12px;
  background: var(--warn-bg);
  color: #5c4010;
  border-radius: 10px;
  font-size: 13px;
}
.content { padding: 18px 22px 40px; }

.toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  align-items: center;
}
.toolbar input, .toolbar select {
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 0 10px;
  background: var(--white);
}
.toolbar input[type="search"] { min-width: 220px; }

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--white);
  max-height: calc(100vh - 210px);
}
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  white-space: nowrap;
}
table.data th {
  position: sticky;
  top: 0;
  background: #efe8d8;
  text-align: left;
  font-weight: 600;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  z-index: 1;
}
table.data td {
  padding: 8px 12px;
  border-bottom: 1px solid #eee6d6;
}
table.data tbody tr { cursor: pointer; }
table.data tbody tr:hover { background: #f7f1e4; }
table.data tbody tr.selected { background: var(--accent-soft); }
.mono { font-family: var(--mono); font-size: 12px; }
.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.pill-paid { background: var(--paid-bg); color: var(--paid); }
.pill-refused { background: var(--refused-bg); color: var(--refused); }
.pill-work { background: var(--accent-soft); color: var(--accent); }
.pill-corr { background: #f8d7c8; color: #8a3b1c; }
.pill-wait { background: var(--warn-bg); color: var(--warn); }
table.data tbody tr.needs-corr { background: #fde8dc; }
table.data tbody tr.needs-corr:hover { background: #f8d7c8; }
.note-cell {
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.seg {
  display: inline-flex;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}
.seg-btn {
  height: 30px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  border-radius: 8px;
  color: var(--ink-soft);
  font-weight: 600;
  font-size: 13px;
}
.seg-btn.active { background: var(--white); color: var(--ink); box-shadow: 0 1px 3px rgba(31,27,22,0.08); }
.filters-bar { align-items: center; }
.period-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
  padding: 12px 14px;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.period-custom {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.period-custom label {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 13px;
  color: var(--ink-soft);
  font-weight: 600;
}
.period-custom input[type="date"] {
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 0 10px;
  background: var(--paper);
}
.toolbar .btn-sm { width: auto; margin: 0; }

/* Drawer */
.drawer-back {
  position: fixed;
  inset: 0;
  background: rgba(31,27,22,0.28);
  z-index: 20;
  display: flex;
  justify-content: flex-end;
}
.drawer {
  width: min(560px, 100%);
  height: 100%;
  background: var(--white);
  box-shadow: var(--shadow);
  overflow: auto;
  padding: 22px;
}
.drawer h3 { margin: 0 0 4px; }
.drawer .sub { color: var(--ink-soft); margin: 0 0 18px; font-size: 13px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.field.span2 { grid-column: 1 / -1; }
.field label { font-size: 12px; font-weight: 600; }
.field input, .field select, .field textarea {
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 10px;
  background: #fff;
  width: 100%;
}
.field textarea { min-height: 72px; resize: vertical; }
.field input:disabled, .field select:disabled, .field textarea:disabled {
  background: var(--paper);
  color: var(--ink-soft);
}
.drawer-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin-bottom: 16px; }
.card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  text-align: left;
  font: inherit;
  color: inherit;
  width: 100%;
}
.card:hover { border-color: var(--accent); }
.card.card-active { border-color: var(--accent); background: var(--accent-soft); }
.card b { display: block; font-size: 22px; margin-top: 4px; }
.card span { font-size: 12px; color: var(--ink-soft); }

.chat {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  margin: 0 0 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 280px;
  overflow: auto;
}
.chat-msg {
  max-width: 92%;
  padding: 8px 10px;
  border-radius: 12px;
  background: var(--white);
  border: 1px solid var(--line);
}
.chat-msg.chat-manager { align-self: flex-start; }
.chat-msg.chat-designer { align-self: flex-end; background: var(--accent-soft); border-color: #c5e0e0; }
.chat-meta { font-size: 11px; color: var(--ink-soft); margin-bottom: 4px; }
.chat-text { font-size: 13px; white-space: pre-wrap; line-height: 1.4; }

.log-item {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
}
.log-item .meta { font-size: 12px; color: var(--ink-soft); margin-bottom: 4px; }
.log-item .diff { font-family: var(--mono); font-size: 11px; white-space: pre-wrap; color: #3d3830; }

.import-box textarea {
  width: 100%;
  min-height: 160px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  font-family: var(--mono);
  font-size: 12px;
}
table.data.static tbody tr { cursor: default; }
table.data.static tbody tr:hover { background: transparent; }
.block-title {
  margin: 22px 0 10px;
  font-size: 16px;
  font-weight: 600;
}
.hint { font-size: 13px; color: var(--ink-soft); line-height: 1.5; }

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  background: var(--ink);
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  z-index: 50;
  font-size: 13px;
}

@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .cards { grid-template-columns: 1fr 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
}
