:root {
  --paper: #F5F0E8;
  --card: #EBE5D8;
  --ink: #1A1A1A;
  --ink-soft: #4A4A48;
  --muted: #8A8A86;
  --line: #D5CDB8;
  --accent: #D94444;
  --serif: Georgia, "DejaVu Serif", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: var(--sans);
  background: var(--paper);
  color: var(--ink);
}

.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 480px;
  margin: 0 auto;
  background: var(--paper);
  position: relative;
}

/* ===== HEADER ===== */
.header {
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  padding: 16px 20px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.logo-section {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}

.logo-image {
  width: 48px;
  height: 48px;
  object-fit: contain;
}

.header-text h1 {
  margin: 0;
  font-size: 1.3rem;
  font-family: var(--serif);
  font-weight: 600;
  color: var(--ink);
}

.header-subtitle {
  margin: 4px 0 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.header-subtitle-small {
  margin: 4px 0 0;
  font-size: 0.82rem;
  color: var(--muted);
  font-family: var(--serif);
}

.header-id {
  margin: 6px 0 0;
  font-size: 0.95rem;
  color: var(--ink-soft);
  font-family: var(--serif);
}

.header-warning {
  margin: 6px 0 0;
  font-size: 0.82rem;
  color: #D94444;
  font-family: var(--sans);
}

.install-button {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 0.85rem;
  cursor: pointer;
  font-weight: 500;
}

/* ===== MAIN CONTENT ===== */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px 0 96px;
  -webkit-overflow-scrolling: touch;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
  animation: fadeIn 0.2s;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ===== CARDS ===== */
.card {
  margin: 0 12px 12px;
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.card-icon {
  font-size: 1.3rem;
  line-height: 1;
}

.card-header h2 {
  margin: 0;
  font-size: 1rem;
  font-family: var(--serif);
  font-weight: 600;
  color: var(--ink);
}

.date-nav-card {
  margin-top: 8px;
}

.date-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 10px;
}

.date-display {
  flex: 1;
  text-align: center;
  font-size: 0.95rem;
  color: var(--ink);
  font-family: var(--serif);
  font-weight: 600;
}

.date-nav-btn {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  border-radius: 999px;
  font-size: 1.35rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.date-nav-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

/* DIAL CARD */
.card-dial .dial-container {
  display: flex;
  align-items: center;
  gap: 16px;
}

.dial-visual {
  position: relative;
  flex-shrink: 0;
}

.dial {
  display: block;
}

.dial-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}

.dial-value {
  font-size: 1.6rem;
  font-family: var(--mono);
  font-weight: 700;
  color: var(--ink);
  line-height: 1;
}

.dial-label {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 4px;
}

.dial-inputs {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dial-inputs label {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.input-label {
  font-size: 0.8rem;
  color: var(--muted);
}

.dial-inputs input {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 0.95rem;
  background: var(--paper);
  color: var(--ink);
}

/* GKI CARD */
.card-gki .gki-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 12px;
}

.gki-large {
  font-size: 2.4rem;
  font-family: var(--mono);
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
}

.gki-info {
  font-size: 0.85rem;
  color: var(--ink-soft);
  max-width: 200px;
}

/* ===== FORM ELEMENTS ===== */
#daily-form {
  padding: 0;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.label-text {
  font-size: 0.85rem;
  color: var(--muted);
  font-family: var(--sans);
}

.form-field textarea,
.form-field input {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-family: var(--sans);
  font-size: 0.95rem;
  background: var(--paper);
  color: var(--ink);
}

.form-field textarea {
  resize: vertical;
  min-height: 60px;
}

/* MEASUREMENTS */
.measurements-grid {
  display: grid;
  gap: 10px;
}

.measurement-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.measurement-row:last-child {
  border-bottom: none;
}

.measurement-label {
  font-size: 0.85rem;
  color: var(--muted);
}

.input-with-unit {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.input-with-unit input {
  width: 70px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 0.95rem;
  background: var(--paper);
  color: var(--ink);
  text-align: right;
}

.unit {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--muted);
}

/* TWO COLUMN INPUTS */
.two-column-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.macro-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.macro-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.medications-list {
  display: grid;
  gap: 10px;
}

.medication-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid rgba(0,0,0,0.05);
}

.medication-row:last-child {
  border-bottom: none;
}

.medication-inputs {
  display: grid;
  grid-template-columns: 1fr 120px;
  gap: 8px;
}

.medication-inputs input {
  width: 100%;
}

.btn-add,
.btn-remove {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 0.85rem;
  cursor: pointer;
}

.btn-remove {
  min-width: 44px;
  padding: 8px;
}

.btn-add {
  margin-left: auto;
}

.bristol-grid {
  display: grid;
  gap: 12px;
}

.bristol-buttons {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
}

.bristol-button {
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
  border-radius: 12px;
  padding: 10px 0;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.bristol-button.active {
  border-color: var(--accent);
  background: rgba(217, 68, 68, 0.15);
  color: var(--accent);
}

.bristol-help {
  color: var(--muted);
  font-size: 0.85rem;
  min-height: 1.3rem;
}

.history-detail {
  margin: 0 12px 12px;
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
}

.history-detail h3 {
  margin: 0 0 10px;
  font-size: 1rem;
  font-family: var(--serif);
}

.history-detail dl {
  display: grid;
  gap: 8px;
}

.history-detail dt {
  font-size: 0.85rem;
  color: var(--muted);
}

.history-detail dd {
  margin: 0;
  font-size: 0.95rem;
  color: var(--ink);
}

.history-detail button {
  margin-top: 12px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  font-size: 0.95rem;
}

.two-small-inputs {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 8px;
  margin-left: 12px;
  min-width: 140px;
}

.two-small-inputs input {
  flex: 1 1 0;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 0.95rem;
  background: var(--paper);
  color: var(--ink);
  text-align: right;
  box-sizing: border-box;
}

/* BLOOD PRESSURE GRID */
.bp-grid {
  display: grid;
  gap: 14px;
}

.bp-column {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bp-time {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink);
}

.bp-inputs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  font-family: var(--mono);
  font-size: 0.85rem;
  box-sizing: border-box;
  min-width: 0;
}

.bp-inputs input,
.bp-inputs span {
  box-sizing: border-box;
  min-width: 0;
}

.bp-inputs input {
  flex: 1 1 40px;
  min-width: 40px;
  padding: 8px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  text-align: center;
  font-size: 0.85rem;
}

.bp-inputs span {
  color: var(--muted);
}

.dot {
  color: var(--line);
}

/* SCALES */
.scales-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.scale-slider {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.scale-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
}

.scale-header span:first-child {
  color: var(--muted);
}

.scale-value {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.scale-input {
  width: 56px;
  min-width: 56px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 0.95rem;
  background: var(--paper);
  color: var(--ink);
  text-align: center;
}

.scale-max {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--muted);
}

.slider {
  width: 100%;
  height: 5px;
  -webkit-appearance: none;
  appearance: none;
  background: linear-gradient(to right, var(--paper) 0%, var(--accent) 100%);
  border-radius: 5px;
  outline: none;
  accent-color: var(--accent);
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: white;
  border: 2px solid var(--accent);
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: white;
  border: 2px solid var(--accent);
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* SUBMIT SECTION */
.submit-section {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 16px 12px 0;
  margin-top: 12px;
  border-top: 1px solid var(--line);
}

.btn-primary {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 12px 20px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  flex: 1;
}

.btn-primary:active {
  opacity: 0.9;
}

.status-message {
  font-size: 0.8rem;
  color: var(--muted);
  flex-shrink: 0;
}

/* ===== HISTORY & TRENDS ===== */
.history-list,
.trends-container {
  padding: 16px 12px;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
  font-size: 0.9rem;
}

.history-item {
  padding: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: background 0.2s;
}

.history-item:active {
  background: rgba(217, 68, 68, 0.05);
}

.history-date {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--ink);
  margin-bottom: 6px;
}

.history-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--muted);
  font-family: var(--mono);
}

.meta-value {
  color: var(--ink-soft);
}

.meta-sep {
  color: var(--line);
}

/* ===== BOTTOM TAB BAR ===== */
.tab-bar {
  display: flex;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 480px;
  margin: 0 auto;
  justify-content: space-around;
  align-items: center;
  height: 64px;
  background: var(--card);
  border-top: 1px solid var(--line);
  z-index: 99;
}

.tab-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: none;
  border: none;
  padding: 8px 12px;
  cursor: pointer;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 500;
  flex: 1;
  height: 100%;
  border-radius: 8px;
  transition: color 0.2s;
}

.tab-button:active,
.tab-button.active {
  color: var(--accent);
}

.tab-icon {
  font-size: 1.3rem;
  line-height: 1;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 480px) {
  .app-container {
    max-width: 100%;
    border-radius: 0;
  }

  .header {
    padding: 12px 16px;
  }

  .main-content {
    padding: 12px 0 80px;
  }

  .card {
    margin: 0 8px 8px;
    padding: 12px;
  }

  .two-column-inputs {
    grid-template-columns: 1fr;
  }

  .bp-grid {
    grid-template-columns: 1fr;
  }
}

/* ===== INPUT PLACEHOLDERS ===== */
input::placeholder,
textarea::placeholder {
  color: var(--muted);
  opacity: 0.6;
}

input::-webkit-calendar-picker-indicator {
  opacity: 0.4;
}

