:root {
  --bg: #faf7f2;
  --card-bg: #ffffff;
  --border: #e4ddd0;
  --text: #2b2420;
  --text-muted: #7a7268;
  --accent: #c1622e;
  --accent-dark: #9c4c22;
  --good: #4c8c5c;
  --danger: #b23b3b;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1815;
    --card-bg: #262220;
    --border: #3a342e;
    --text: #f2ede5;
    --text-muted: #b3a99b;
    --accent: #e08847;
    --accent-dark: #f0a468;
    --good: #7cbf8b;
    --danger: #e06868;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

.hidden {
  display: none !important;
}

button {
  font-family: inherit;
  cursor: pointer;
}

input,
select {
  font-family: inherit;
  font-size: 1rem;
}

/* Login */

#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

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

.login-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 24px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.login-card h1 {
  margin: 0 0 4px;
  font-size: 1.5rem;
}

.subtitle {
  color: var(--text-muted);
  margin: 0 0 20px;
}

.login-card input {
  width: 100%;
  padding: 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  margin-bottom: 12px;
}

.login-card button {
  width: 100%;
  padding: 14px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
}

.error {
  color: var(--danger);
  margin: 8px 0 0;
}

/* App shell */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}

.app-header h1 {
  font-size: 1.25rem;
  margin: 0;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 1.1rem;
  padding: 8px 12px;
  min-width: 44px;
  min-height: 44px;
}

.dogs-container {
  display: grid;
  gap: 16px;
  padding: 16px;
  max-width: 640px;
  margin: 0 auto;
}

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

/* Dog card */

.dog-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.dog-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.dog-emoji {
  font-size: 1.8rem;
}

.dog-name {
  flex: 1;
  margin: 0;
  font-size: 1.2rem;
}

.lie-badge {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.9rem;
  white-space: nowrap;
}

.meals {
  display: grid;
  gap: 14px;
  grid-template-columns: 1fr;
}

@media (min-width: 480px) {
  .meals {
    grid-template-columns: 1fr 1fr;
  }
}

.meal {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}

.meal-title {
  margin: 0 0 8px;
  font-size: 1rem;
  color: var(--text-muted);
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  min-height: 44px;
}

.toggle-row input[type='checkbox'] {
  width: 24px;
  height: 24px;
  accent-color: var(--good);
  flex-shrink: 0;
}

.treat-row {
  position: relative;
}

.lie-flag {
  margin-left: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 10px;
  min-width: 44px;
  min-height: 44px;
  color: var(--text-muted);
}

.lie-flag-emoji {
  font-size: 1.3rem;
  line-height: 1;
}

.lie-flag-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  line-height: 1;
}

.lie-flag:active {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.meal-doses {
  margin-top: 6px;
  border-top: 1px dashed var(--border);
}

.dose-row {
  font-size: 0.92rem;
}

.other-doses h4 {
  margin: 12px 0 4px;
  font-size: 0.95rem;
  color: var(--text-muted);
}

.history-toggle-btn {
  margin-top: 14px;
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  color: var(--accent-dark);
  font-weight: 600;
}

.history-panel {
  margin-top: 10px;
  overflow-x: auto;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.history-table th,
.history-table td {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

/* Settings modal */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 10;
}

@media (min-width: 640px) {
  .modal {
    align-items: center;
  }
}

.modal-content {
  background: var(--card-bg);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 16px;
}

@media (min-width: 640px) {
  .modal-content {
    border-radius: var(--radius);
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.modal-content section {
  margin-bottom: 20px;
}

.modal-content h3 {
  margin: 0 0 8px;
}

.settings-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.settings-row input {
  flex: 1;
  min-width: 80px;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.settings-row button,
.inline-form button {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--accent);
  color: #fff;
  min-height: 40px;
}

.settings-row .danger {
  background: var(--danger);
}

.med-fixed-name {
  flex-basis: 100%;
  font-weight: 600;
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.inline-form input,
.inline-form select {
  flex: 1;
  min-width: 90px;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
