@font-face { font-family: "Open Sans"; font-style: normal; font-weight: 400; font-display: swap; src: url("/fonts/open-sans-400.ttf") format("truetype"); }
@font-face { font-family: "Open Sans"; font-style: normal; font-weight: 600; font-display: swap; src: url("/fonts/open-sans-600.ttf") format("truetype"); }
@font-face { font-family: "Open Sans"; font-style: normal; font-weight: 700; font-display: swap; src: url("/fonts/open-sans-700.ttf") format("truetype"); }
@font-face { font-family: "Patrick Hand"; font-style: normal; font-weight: 400; font-display: swap; src: url("/fonts/patrick-hand.ttf") format("truetype"); }

:root {
  --bg: #ddcfae;
  --surface: #f0e6cc;
  --text: #2e2416;
  --muted: #6b5c42;
  --border: #c9b48c;
  --primary: #5b7fdb;
  --primary-dark: #4a68b8;
  --danger: #b3455a;
  --line-color: rgba(107, 84, 56, 0.22);
  --margin-color: rgba(178, 74, 74, 0.5);
  --fade-text: #b8a880;
  --ok-color: #4f9e6f;
  --missing-color: #c1544f;
  --radius: 16px;
  --font-body: "Open Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-hand: "Patrick Hand", var(--font-body);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

:focus-visible { outline: 3px solid var(--primary); outline-offset: 3px; }
button:disabled { opacity: 0.6; cursor: wait; }
#logout-retry[hidden] { display: none; }
.dot-ok { background: var(--ok-color); }
.dot-missing { background: var(--missing-color); }
.dot-today { background: var(--primary); }
.mood-option[data-value="-3"] { --mood-color: #5b7fdb; }
.mood-option[data-value="-2"] { --mood-color: #7c93df; }
.mood-option[data-value="-1"] { --mood-color: #97a2c4; }
.mood-option[data-value="0"] { --mood-color: #9aa0b4; }
.mood-option[data-value="1"] { --mood-color: #c9a26e; }
.mood-option[data-value="2"] { --mood-color: #dd8f4f; }
.mood-option[data-value="3"] { --mood-color: #e2793a; }

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1f1a16;
    --surface: #2a231c;
    --text: #ece4d6;
    --muted: #a99d8a;
    --border: #3d332a;
    --primary: #8aa4ee;
    --primary-dark: #6684d9;
    --danger: #e08a95;
    --line-color: rgba(255, 255, 255, 0.06);
    --margin-color: rgba(224, 120, 120, 0.28);
    --fade-text: #5a4f40;
    --ok-color: #6fce93;
    --missing-color: #e0807a;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: calc(16px + var(--safe-top)) 16px calc(24px + var(--safe-bottom));
}

@media (max-width: 360px) {
  .app {
    padding-left: 12px;
    padding-right: 12px;
  }
  .mood-options,
  .energy-options {
    gap: 4px;
  }
  .mood-option {
    min-height: 40px;
    font-size: 1.2rem;
  }
  .clock-digits,
  .clock-colon {
    font-size: 1.5rem;
  }
  .clock-btn {
    width: 30px;
  }
}

@media (min-width: 900px) {
  .app {
    max-width: clamp(900px, 88vw, 1440px);
  }
}

.view[hidden] {
  display: none;
}

.view-centered {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

/* "Página de caderno": pauta horizontal + margem vermelha à esquerda */
.page {
  position: relative;
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 27px,
    var(--line-color) 27px,
    var(--line-color) 28px
  );
  background-position: 0 64px;
  padding-left: 32px;
  border-left: 3px solid var(--margin-color);
}

.login-card {
  width: 100%;
  max-width: 360px;
}

h1 {
  font-family: var(--font-hand);
  font-size: 1.7rem;
  margin: 0 0 4px;
  font-weight: 400;
}

h2 {
  font-family: var(--font-hand);
  font-size: 1.4rem;
  margin: 0 0 4px;
  font-weight: 400;
}

.subtitle {
  color: var(--muted);
  margin: 0 0 20px;
  font-size: 0.95rem;
}

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

.topbar h1 {
  margin: 0;
}

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

.export-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.export-actions .btn {
  width: auto;
  font-size: 0.85rem;
  padding: 8px 14px;
  min-height: 38px;
}

/* Abas (mobile) */
.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.tab-btn {
  flex: 1;
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
}

.tab-btn[aria-selected="true"] {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.panel[hidden] {
  display: none;
}

@media (min-width: 900px) {
  .tabs {
    display: none;
  }
  .panels {
    display: grid;
    grid-template-columns: minmax(380px, 460px) 1fr;
    gap: 32px;
    align-items: start;
  }
  .panel[hidden] {
    display: block;
  }
  .panel#panel-registrar {
    position: sticky;
    top: 16px;
  }
  .card.page {
    padding: 30px;
    padding-left: 42px;
  }
  .field-notes {
    margin-top: 22px;
  }
  .field-notes textarea {
    min-height: 260px;
  }
}

.field {
  display: block;
  margin-bottom: 18px;
}

.field > span {
  display: block;
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.field b {
  color: var(--primary);
  font-weight: 700;
}

input,
textarea,
select {
  width: 100%;
  font-family: var(--font-body);
  font-size: 16px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

input:focus,
textarea:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.field-notes textarea {
  min-height: 220px;
  line-height: 1.7;
  font-size: 1.05rem;
  resize: vertical;
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 31px,
    var(--line-color) 31px,
    var(--line-color) 32px
  );
  background-position: 0 20px;
}

fieldset {
  border: none;
  padding: 0;
  margin: 0 0 18px;
}

legend {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 8px;
  padding: 0;
}

.mood-options {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.mood-option {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  font-size: 1.4rem;
  line-height: 1;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.mood-option[aria-checked="true"] {
  border-color: var(--mood-color, var(--primary));
  background: color-mix(in srgb, var(--mood-color, var(--primary)) 20%, var(--bg));
  transform: scale(1.12);
  box-shadow: 0 2px 8px color-mix(in srgb, var(--mood-color, var(--primary)) 40%, transparent);
}

.mood-caption {
  margin: 8px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
  min-height: 1.2em;
  text-align: center;
}

.energy-options {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.energy-option {
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  font-weight: 700;
  color: var(--muted);
  font-family: var(--font-body);
}

.energy-option[aria-checked="true"] {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 18%, var(--bg));
  color: var(--primary);
}

/* Relógio de números (horas de sono) */
.clock-input {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
}

.clock-segment {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.clock-digits {
  font-family: "Open Sans", monospace;
  font-size: 1.8rem;
  font-weight: 700;
  min-width: 2.2ch;
  text-align: center;
  color: var(--text);
}

.clock-colon {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--muted);
  padding-bottom: 22px;
}

.clock-btn {
  width: 36px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--primary);
  font-size: 0.8rem;
  cursor: pointer;
}

.clock-clear {
  margin-left: 10px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.85rem;
  text-decoration: underline;
  cursor: pointer;
  min-height: 32px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 12px 20px;
  border-radius: 12px;
  border: none;
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:active {
  background: var(--primary-dark);
}

.btn-ghost {
  width: auto;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 8px 14px;
  min-height: 36px;
}

.error {
  color: var(--danger);
  font-size: 0.9rem;
  margin: -4px 0 12px;
}

.feedback {
  font-size: 0.9rem;
  color: var(--primary);
  margin: -4px 0 12px;
}

.diary-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.diary-stats[hidden] {
  display: none;
}

.stat-tile {
  text-align: center;
  padding: 10px 6px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
}

.stat-tile .stat-value {
  display: block;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--primary);
}

.stat-tile .stat-label {
  font-size: 0.72rem;
  color: var(--muted);
}

.diario-columns {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

@media (min-width: 900px) {
  .diario-columns {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 28px;
    align-items: start;
  }
}

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

.calendar-title {
  font-family: var(--font-hand);
  font-size: 1.15rem;
  color: var(--text);
}

.calendar-nav-btn {
  width: 34px;
  height: 34px;
  min-width: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
}

.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 4px;
}

.calendar-weekdays span {
  text-align: center;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--muted);
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.calendar-day {
  font-family: var(--font-body);
  font-size: 0.82rem;
  border: none;
  background: transparent;
  cursor: pointer;
  aspect-ratio: 1;
  min-height: 36px;
  border-radius: 10px;
  color: var(--text);
}

.calendar-day.is-outside {
  color: var(--fade-text);
}

.calendar-day.has-entry:not(.is-outside) {
  background: color-mix(in srgb, var(--ok-color) 32%, var(--bg));
}

.calendar-day.is-missing:not(.is-outside) {
  background: color-mix(in srgb, var(--missing-color) 26%, var(--bg));
}

.calendar-day.is-today {
  background: var(--primary) !important;
  color: #fff;
  font-weight: 700;
}

.calendar-day.is-selected {
  box-shadow: 0 0 0 2px var(--text);
}

.calendar-legend {
  display: flex;
  gap: 12px;
  margin-top: 12px;
  font-size: 0.7rem;
  color: var(--muted);
}

.calendar-legend .dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 4px;
}

.day-detail {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
}

.day-detail-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.day-detail-header .date-label {
  font-family: var(--font-hand);
  font-size: 1.1rem;
  color: var(--text);
}

.day-detail-header .emoji {
  font-size: 1.5rem;
}

.day-detail .meta {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 10px;
}

.day-detail .notes-text {
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--text);
  margin: 0 0 16px;
  white-space: pre-wrap;
}

.day-detail-empty {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 14px;
}

.day-detail-actions {
  display: flex;
  gap: 10px;
}

.day-detail-actions .btn {
  width: auto;
  flex: 1;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--primary);
  color: var(--primary);
}

.btn-delete {
  flex: 0;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 0 16px;
}
