/* Elena AI Cabinet — calm medical UI
   Warm neutral background, deep teal accent, generous whitespace.
   Mobile-first; expands to 3-column desktop. */

:root {
  /* warm neutral surfaces */
  --bg: #f5f1ea;        /* paper */
  --bg-2: #efeae0;
  --surface: #ffffff;
  --ink: #20221f;
  --ink-2: #4b4d49;
  --ink-3: #7c7e79;

  /* deep teal accent */
  --accent: #1f4f4a;
  --accent-2: #2c6f68;
  --accent-soft: #d9e6e3;

  --warn: #b3601a;
  --danger: #a23a2e;
  --good: #3a6b3a;

  --line: #e3ddd0;
  --line-2: #d8d1c1;

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

  --shadow-1: 0 1px 2px rgba(20, 24, 22, 0.04), 0 1px 1px rgba(20, 24, 22, 0.02);
  --shadow-2: 0 4px 16px rgba(20, 24, 22, 0.06);

  --font-sans: "Satoshi", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-display: "Cabinet Grotesk", "Satoshi", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "ss01", "cv11";
  line-height: 1.45;
}

button, input, textarea, select {
  font: inherit;
  color: inherit;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-2); }

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0;
}
h1 { font-size: 1.4rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1.0rem; }
h4 { font-size: 0.92rem; color: var(--ink-2); text-transform: uppercase; letter-spacing: .06em; }

.muted { color: var(--ink-3); }
.small { font-size: 0.85rem; }

/* Boot */
.boot {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100vh; gap: 12px; color: var(--accent);
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 14px;
  background: var(--accent); color: #fff;
  border: 1px solid var(--accent);
  border-radius: var(--r);
  cursor: pointer;
  font-weight: 500;
  transition: background .12s ease, transform .12s ease;
}
.btn:hover { background: var(--accent-2); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn.secondary {
  background: var(--surface); color: var(--ink); border-color: var(--line-2);
}
.btn.secondary:hover { background: var(--bg-2); }
.btn.ghost {
  background: transparent; border-color: transparent; color: var(--ink-2);
}
.btn.ghost:hover { background: var(--bg-2); color: var(--ink); }
.btn.small { padding: 6px 10px; font-size: .88rem; }
.btn.danger { background: var(--danger); border-color: var(--danger); }

.input, .select, .textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: var(--r);
  padding: 10px 12px;
  outline: none;
  transition: border-color .12s ease, box-shadow .12s ease;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.textarea { min-height: 80px; resize: vertical; }
.label {
  display: block;
  font-size: .82rem;
  color: var(--ink-2);
  margin-bottom: 4px;
  letter-spacing: .02em;
}
.field { margin-bottom: 12px; }

.row { display: flex; gap: 8px; align-items: center; }
.col { display: flex; flex-direction: column; gap: 8px; }
.spacer { flex: 1; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px;
  font-size: .76rem; font-weight: 500;
  background: var(--accent-soft); color: var(--accent);
}
.badge.warn { background: #f5e4d4; color: var(--warn); }
.badge.muted { background: var(--bg-2); color: var(--ink-3); }
.badge.danger { background: #f3dad6; color: var(--danger); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 16px;
  box-shadow: var(--shadow-1);
}
.card + .card { margin-top: 12px; }

.divider { height: 1px; background: var(--line); margin: 12px 0; }

/* ==== Login ==== */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 10%, rgba(31,79,74,0.06), transparent 50%),
    radial-gradient(circle at 80% 90%, rgba(31,79,74,0.04), transparent 50%),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 28px;
  box-shadow: var(--shadow-2);
}
.login-card .brand {
  display: flex; align-items: center; gap: 10px; margin-bottom: 20px;
  color: var(--accent);
}
.login-card h1 { font-size: 1.25rem; color: var(--ink); }
.login-card .subtitle { color: var(--ink-3); margin-top: 4px; }
.pin-input { letter-spacing: .35em; text-align: center; font-size: 1.4rem; }

/* ==== App shell ==== */
.app {
  min-height: 100vh;
  display: flex; flex-direction: column;
}
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  position: sticky; top: 0; z-index: 10;
}
.topbar .brand {
  display: flex; align-items: center; gap: 8px; color: var(--accent);
  font-family: var(--font-display); font-weight: 700;
}
.topbar .pill {
  padding: 4px 10px; border-radius: 999px; background: var(--bg-2);
  font-size: .78rem; color: var(--ink-2);
}

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr;
  min-height: 0;
}
.bottom-nav {
  position: sticky; bottom: 0;
  display: flex; justify-content: space-around;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding: 6px 0 max(6px, env(safe-area-inset-bottom));
  z-index: 10;
}
.bottom-nav button {
  flex: 1;
  background: none; border: none;
  color: var(--ink-3);
  font-size: .76rem;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px;
  cursor: pointer;
}
.bottom-nav button.active { color: var(--accent); }
.bottom-nav .dot {
  width: 22px; height: 22px; border-radius: 6px;
  display: grid; place-items: center;
}

.pane { padding: 14px; overflow: auto; }

/* Patients list */
.patients-list .group { margin-bottom: 18px; }
.patients-list .group h4 { margin-bottom: 8px; }
.patient-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--r);
  border: 1px solid var(--line);
  background: var(--surface);
  margin-bottom: 6px;
  cursor: pointer;
}
.patient-item:hover { border-color: var(--line-2); }
.patient-item.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.patient-item .name { font-weight: 500; }
.patient-item .meta { font-size: .82rem; color: var(--ink-3); }

/* Chat */
.chat {
  display: flex; flex-direction: column;
  min-height: 0; height: 100%;
}
.chat-header {
  display: flex; gap: 8px; flex-wrap: wrap;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.chat-body {
  flex: 1; overflow: auto;
  padding: 14px;
  background: var(--bg);
}
.msg {
  max-width: 78ch;
  margin: 0 auto 12px;
  padding: 12px 14px;
  border-radius: var(--r-lg);
  background: var(--surface);
  border: 1px solid var(--line);
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg.doctor {
  background: var(--accent-soft);
  border-color: transparent;
  margin-right: 0; margin-left: auto;
}
.msg.assistant { }
.msg .meta {
  font-size: .72rem; color: var(--ink-3); margin-top: 6px;
  display: flex; gap: 8px; align-items: center;
}
.msg.draft-warning {
  border-left: 3px solid var(--warn);
}

.composer {
  display: flex; gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.composer .textarea {
  min-height: 44px; max-height: 180px;
}

/* Patient card */
.patient-card .tabs {
  display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.patient-card .tab {
  padding: 8px 12px;
  background: none; border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  color: var(--ink-2);
  font-weight: 500;
  font-size: .9rem;
}
.patient-card .tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.timeline-item {
  padding: 10px 12px;
  border-left: 2px solid var(--line);
  margin-left: 6px;
  margin-bottom: 8px;
}
.timeline-item .when { font-size: .78rem; color: var(--ink-3); }
.timeline-item .what { font-weight: 500; }

/* Usage panel */
.kpi {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.kpi .item {
  background: var(--bg-2); padding: 10px 12px; border-radius: var(--r);
}
.kpi .item .v { font-size: 1.3rem; font-weight: 700; color: var(--accent); }
.kpi .item .k { font-size: .75rem; color: var(--ink-3); text-transform: uppercase; letter-spacing: .06em; }

.bar {
  height: 6px; background: var(--bg-2); border-radius: 999px; overflow: hidden;
  margin-top: 6px;
}
.bar > div { height: 100%; background: var(--accent); transition: width .2s ease; }
.bar.warn > div { background: var(--warn); }
.bar.danger > div { background: var(--danger); }

/* Modal */
.modal-bg {
  position: fixed; inset: 0; background: rgba(20,24,22,.45);
  display: grid; place-items: center; padding: 16px; z-index: 50;
}
.modal {
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: 22px;
  max-width: 540px; width: 100%;
  max-height: 90vh; overflow: auto;
  box-shadow: var(--shadow-2);
}

/* Empty state */
.empty {
  padding: 32px 20px; text-align: center; color: var(--ink-3);
}

.list-item {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
  margin-bottom: 8px;
}
.list-item .title { font-weight: 500; }
.list-item .meta { font-size: .82rem; color: var(--ink-3); margin-top: 2px; }

.tag {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: .76rem; background: var(--bg-2); color: var(--ink-2);
  margin-right: 4px;
}

/* ==== Responsive ==== */
@media (min-width: 980px) {
  .layout {
    grid-template-columns: 320px 1fr 380px;
    height: calc(100vh - 52px);
  }
  .pane { border-right: 1px solid var(--line); }
  .pane.right { border-right: none; border-left: 1px solid var(--line); }
  .bottom-nav { display: none; }
  .topbar .nav-tabs { display: flex; gap: 4px; margin-left: 12px; }
  .topbar .nav-tabs button {
    background: none; border: none; padding: 6px 10px; border-radius: 6px;
    color: var(--ink-2); cursor: pointer; font-weight: 500;
  }
  .topbar .nav-tabs button.active { background: var(--accent-soft); color: var(--accent); }
}
@media (max-width: 979px) {
  .layout { grid-template-columns: 1fr; }
  .pane { padding: 14px 14px 80px; }
  .topbar .nav-tabs { display: none; }
  .topbar .pill { display: none; }
  .topbar .pill:last-of-type { display: inline-flex; }
  .topbar { padding: 8px 12px; }
  .topbar .brand { font-size: 0.95rem; }
  .layout > .pane { display: none; }
  .layout > .pane.is-current { display: block; }
  .chat-header { gap: 6px; padding: 10px 12px; }
  .chat-header .select { max-width: none; flex: 1; min-width: 130px; }
}
