:root {
  color-scheme: dark;
  --bg: #121212;
  --panel: #1c1c1a;
  --panel-2: #24231f;
  --text: #f3f0e8;
  --muted: #aaa49a;
  --line: #3a3933;
  --accent: #4fd1a5;
  --accent-strong: #25b486;
  --danger: #ff7a7a;
  --shadow: rgba(0, 0, 0, 0.35);
}

:root[data-theme='light'] {
  color-scheme: light;
  --bg: #f5f4ef;
  --panel: #ffffff;
  --panel-2: #eceae2;
  --text: #1e1d1a;
  --muted: #68645d;
  --line: #d8d4ca;
  --accent: #0f9f72;
  --accent-strong: #087a58;
  --danger: #b72f3c;
  --shadow: rgba(35, 32, 25, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(135deg, rgba(79, 209, 165, 0.09), transparent 34%),
    linear-gradient(315deg, rgba(255, 122, 122, 0.08), transparent 30%),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

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

button,
.file-button {
  border: 1px solid var(--line);
  border-radius: 7px;
  min-height: 34px;
  padding: 0 12px;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}

button:hover,
.file-button:hover {
  border-color: var(--accent);
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--bg);
  color: var(--text);
  padding: 8px 10px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 209, 165, 0.18);
}

textarea {
  resize: vertical;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.1;
}

h2 {
  font-size: 14px;
}

h3 {
  font-size: 15px;
}

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

.app-shell {
  min-height: 100vh;
}

.auth-view,
.phonebook-view {
  display: none;
}

.app-shell[data-view='auth'] .auth-view,
.app-shell[data-view='phonebook'] .phonebook-view {
  display: block;
}

.auth-view {
  min-height: 100vh;
  padding: 18px;
  place-items: center;
}

.app-shell[data-view='auth'] .auth-view {
  display: grid;
}

.auth-box {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  box-shadow: 0 22px 70px var(--shadow);
  padding: 18px;
}

.brand-row,
.topbar,
.sidebar-head,
.tool-row,
.list-head,
.form-actions,
.topbar-actions,
.contact-actions,
.contact-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.stack {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.setup-tools {
  display: flex;
  gap: 8px;
}

.eyebrow {
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.muted,
.status {
  color: var(--muted);
}

.status {
  min-height: 18px;
  font-size: 12px;
}

.status.error,
.danger-text {
  color: var(--danger);
}

.primary {
  border-color: transparent;
  background: var(--accent);
  color: #071511;
  font-weight: 750;
}

.primary:hover {
  border-color: transparent;
  background: var(--accent-strong);
}

.ghost {
  background: transparent;
}

.icon-button {
  width: 34px;
  min-width: 34px;
  padding: 0;
  font-size: 16px;
}

.mini {
  min-height: 26px;
  padding: 0 8px;
  font-size: 12px;
  background: transparent;
}

.compact {
  min-height: 30px;
  padding: 0 9px;
}

.phonebook-view {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 14px;
}

.topbar {
  min-height: 58px;
}

.topbar-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.file-button input {
  display: none;
}

.workspace {
  display: grid;
  grid-template-columns: 235px minmax(0, 1fr);
  gap: 12px;
  min-height: calc(100vh - 86px);
}

.sidebar,
.content {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 95%, transparent);
  box-shadow: 0 14px 40px var(--shadow);
}

.sidebar {
  padding: 12px;
  align-self: start;
  position: sticky;
  top: 14px;
}

.category-list {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.category-item {
  width: 100%;
  display: grid;
  align-items: stretch;
  gap: 5px;
  min-height: 42px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: transparent;
}

.category-item.active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 16%, transparent);
}

.category-select,
.category-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.category-select {
  min-height: 24px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  text-align: left;
}

.category-select:hover {
  border: 0;
}

.category-select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.category-select strong {
  color: var(--muted);
  font-size: 12px;
}

.category-actions {
  justify-content: flex-start;
}

.inline-form {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 6px;
  margin-top: 10px;
}

.content {
  padding: 12px;
  min-width: 0;
}

.tool-row {
  align-items: end;
}

.search-field {
  flex: 1;
  min-width: 180px;
}

.contact-form {
  display: grid;
  grid-template-columns: minmax(140px, 1.1fr) minmax(130px, 0.9fr) minmax(130px, 0.75fr) auto;
  gap: 8px;
  margin: 12px 0;
  align-items: end;
}

.notes-field {
  grid-column: 1 / 4;
}

.form-actions {
  align-self: stretch;
  flex-direction: column;
  justify-content: end;
}

.form-actions button {
  width: 100%;
}

.list-head {
  min-height: 28px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
  font-size: 12px;
  color: var(--muted);
}

.contact-list {
  display: grid;
  gap: 8px;
}

.contact-card,
.empty-state {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  padding: 10px;
}

.contact-main {
  align-items: start;
}

.contact-main span {
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 11px;
  padding: 3px 8px;
}

.contact-card p {
  color: var(--muted);
  margin-top: 7px;
  line-height: 1.35;
  white-space: pre-wrap;
}

.contact-actions {
  justify-content: flex-start;
  margin-top: 8px;
}

.empty-state {
  color: var(--muted);
  text-align: center;
}

@media (max-width: 760px) {
  .phonebook-view {
    padding: 10px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions,
  .tool-row {
    width: 100%;
    justify-content: flex-start;
  }

  .workspace {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .sidebar {
    position: static;
  }

  .category-list {
    grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  }

  .contact-form {
    grid-template-columns: 1fr;
  }

  .notes-field {
    grid-column: auto;
  }

  .form-actions {
    flex-direction: row;
  }
}

@media (max-width: 430px) {
  body {
    font-size: 13px;
  }

  .topbar-actions > *,
  .tool-row > * {
    flex: 1;
  }

  .inline-form {
    grid-template-columns: 1fr;
  }
}
