:root {
  --bg: #f3f5fa;
  --panel: #ffffff;
  --panel-2: #f8f9fd;
  --text: #10182f;
  --muted: #65708d;
  --line: #dde3ef;
  --accent: #3150d4;
  --accent-soft: #e9edff;
  --danger: #b42318;
  --ok: #147a52;
  --warn: #a3560a;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}
button, input, textarea { font: inherit; color: inherit; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px 14px calc(10px + env(safe-area-inset-top, 0px));
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.brand { min-width: 0; margin-right: auto; display: grid; gap: 1px; }
.brand b { font-size: 17px; }
.brand span { color: var(--muted); font-size: 12px; }

.layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 16px;
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: 16px;
}

.sidebar { display: grid; align-content: start; gap: 12px; position: sticky; top: 70px; }
.main { display: grid; gap: 14px; min-width: 0; }

.panel, .birthdays {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(12, 24, 48, .05);
}

.birthdays { padding: 12px; }
.birthdays h2, .section-title {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.birthday-toggle {
  all: unset;
  cursor: pointer;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  width: 100%;
}
.birthday-toggle::after {
  content: "▾";
  color: var(--muted);
  font-size: 12px;
}
.birthday-toggle.open::after { content: "▴"; }
.birthday-toggle span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.birthday-toggle small {
  color: var(--muted);
  font-weight: 650;
  letter-spacing: 0;
  text-transform: none;
}

.input, .textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 7px 9px;
  background: transparent;
}
.input:hover, .textarea:hover { border-color: var(--line); }
.input:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--panel);
}
.input.box, .textarea.box, .search { border-color: var(--line); background: var(--panel); }
.textarea { resize: vertical; min-height: 64px; }
.title-input { font-weight: 700; font-size: 22px; color: #0b1f4d; }
.name-input { font-weight: 650; }

.btn {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 7px 11px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 650; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 8px; font-size: 12px; }
.btn:disabled { opacity: .45; cursor: default; }

.group-list {
  position: relative;
  display: grid;
  gap: 4px;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.group-picker {
  all: unset;
  cursor: pointer;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 7px;
  background: var(--accent-soft);
  color: #0b1f4d;
  font-weight: 700;
}
.group-picker::after {
  content: "▾";
  color: var(--muted);
  font-size: 12px;
  margin-left: 2px;
}
.group-picker.open::after { content: "▴"; }
.group-picker span,
.group span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.group-picker small {
  color: var(--muted);
  font-weight: 600;
}
.group-options {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 12;
  max-height: min(520px, 58vh);
  overflow: auto;
  overscroll-behavior: contain;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 14px 34px rgba(12, 24, 48, .16);
}
.group-options.open {
  display: grid;
  gap: 4px;
}
.group {
  all: unset;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 7px;
}
.group:hover { background: var(--panel-2); }
.group.active { background: var(--accent-soft); color: #0b1f4d; font-weight: 650; }
.group small { color: var(--muted); font-weight: 400; }

.header-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.header-row .title-input { flex: 1 1 280px; }

.card { padding: 13px; display: grid; gap: 10px; }
.row { display: grid; grid-template-columns: minmax(0, 1fr) 150px auto; gap: 8px; align-items: start; }
.asset-row { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, .8fr) auto auto; gap: 8px; align-items: center; }
.contact-top { display: grid; grid-template-columns: minmax(0, 1fr) 150px auto; gap: 8px; align-items: start; }
.contact-top [data-action="deletePerson"] { justify-self: end; }
.field { display: grid; gap: 3px; }
.label { color: var(--muted); font-size: 12px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

.chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 4px 3px 9px;
  border-radius: 999px;
  color: #0b1f4d;
  background: var(--accent-soft);
  font-weight: 550;
  font-size: 13px;
}
.chip button { border: 0; background: transparent; color: var(--muted); cursor: pointer; }
.chip-add { max-width: 170px; border: 1px dashed var(--line); border-radius: 999px; padding: 4px 10px; }

.last {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  padding: 9px 11px;
  border-radius: 8px;
  background: var(--panel-2);
}
.pill { border-radius: 999px; padding: 3px 8px; font-size: 11px; font-weight: 650; white-space: nowrap; }
.pill.ok { color: var(--ok); background: #e4f6ed; }
.pill.warn { color: var(--warn); background: #fff1df; }
.pill.none { color: var(--muted); background: var(--line); }

.meeting-form { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 8px; }
.meeting-form .full { grid-column: 1 / -1; }
.history { display: grid; gap: 6px; }
.meeting-item { display: grid; grid-template-columns: 90px minmax(0, 1fr) auto; gap: 8px; border-left: 3px solid var(--line); padding: 7px 9px; }

.bd-item { display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: 8px; margin-top: 8px; }
.bd-item b { color: var(--accent); font-variant-numeric: tabular-nums; }
.bd-item small { display: block; color: var(--muted); }

.empty { padding: 20px; text-align: center; color: var(--muted); }
.offline { padding: 8px 14px; color: var(--warn); background: #fff1df; border-bottom: 1px solid #ffd5a1; }
.auth-screen { min-height: calc(100vh - 86px); display: grid; place-items: center; padding: 18px; }
.auth-card {
  max-width: 520px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 10px 30px rgba(11, 31, 77, .08);
}
.auth-card h1 { margin: 0 0 10px; font-size: 22px; color: var(--text); }
.auth-card p { margin: 8px 0 0; color: var(--muted); line-height: 1.45; }
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 30;
  background: #0b1f4d;
  color: white;
  padding: 9px 13px;
  border-radius: 8px;
}

.scrim { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 14px; background: rgba(10, 16, 32, .42); }
.dialog { width: min(900px, 100%); max-height: 88vh; display: grid; grid-template-rows: auto auto 1fr auto; background: var(--panel); border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
.dialog-head, .dialog-foot, .dialog-options { padding: 12px 14px; border-bottom: 1px solid var(--line); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.dialog-options label { display: inline-flex; align-items: center; gap: 5px; }
.dialog-head b { margin-right: auto; }
.dialog-foot { border-top: 1px solid var(--line); border-bottom: 0; justify-content: flex-end; }
.dialog-body { padding: 12px 14px; overflow: auto; }
.export-text { min-height: 360px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 12px; }
  .sidebar { position: static; }
  .group-options {
    position: static;
    max-height: 34vh;
    padding: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }
  .row, .asset-row, .contact-top, .meeting-form { grid-template-columns: minmax(0, 1fr); }
  .topbar { flex-wrap: wrap; }
}
