@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Manrope:wght@600;700;800&display=swap');

:root {
  --green-950: #0c3026;
  --green-800: #174c3c;
  --green-700: #1f654f;
  --green-100: #dceee7;
  --green-50: #eef7f3;
  --cream: #f7f5ef;
  --surface: #ffffff;
  --ink: #18312a;
  --muted: #6f7e78;
  --line: #e5e8e4;
  --sun: #f4b942;
  --night: #7c72c9;
  --danger: #b94040;
  --shadow: 0 12px 35px rgba(20, 61, 48, .08);
  --radius-lg: 24px;
  --radius-md: 14px;
  font-family: "DM Sans", system-ui, sans-serif;
  color: var(--ink);
  background: var(--cream);
  font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--cream); color: var(--ink); }
button, input, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
h1, h2, h3, p { margin-top: 0; }
h1, h2, h3, .brand { font-family: "Manrope", sans-serif; }
h1 { margin-bottom: 8px; font-size: clamp(2rem, 5vw, 3.15rem); line-height: 1.08; letter-spacing: -.045em; }
h2 { margin-bottom: 0; font-size: clamp(1.35rem, 3vw, 1.7rem); letter-spacing: -.025em; }
.muted { color: var(--muted); line-height: 1.6; }
.eyebrow { margin-bottom: 8px; color: var(--green-700); font-size: .74rem; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }

.login-shell { min-height: 100vh; display: grid; place-content: center; gap: 22px; padding: 24px; background: radial-gradient(circle at 50% 0, #e1f1e9, transparent 45%), var(--cream); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; color: var(--green-950); }
.brand-login { justify-content: center; font-size: 1.2rem; }
.brand-icon { display: block; width: 36px; height: 36px; border: 2px solid rgba(23, 76, 60, .14); border-radius: 11px; object-fit: cover; box-shadow: 0 5px 15px rgba(23, 76, 60, .22); }
.login-card { width: min(430px, calc(100vw - 32px)); padding: clamp(26px, 6vw, 44px); border: 1px solid rgba(255,255,255,.8); border-radius: var(--radius-lg); background: rgba(255,255,255,.92); box-shadow: var(--shadow); }
.login-card h1 { font-size: 2rem; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 22px 0; padding: 5px; border-radius: 12px; background: var(--green-50); }
.auth-tabs button { min-height: 40px; border: 0; border-radius: 9px; color: var(--muted); background: transparent; font-weight: 700; }
.auth-tabs button[aria-selected="true"] { color: var(--green-950); background: #fff; box-shadow: 0 3px 10px rgba(20,61,48,.08); }
label { display: block; margin-bottom: 8px; font-size: .9rem; font-weight: 700; }
input, select { width: 100%; min-height: 50px; margin-bottom: 18px; padding: 0 14px; border: 1px solid #d9dedb; border-radius: 11px; outline: 0; color: var(--ink); background: #fff; transition: border-color .2s, box-shadow .2s; }
input:focus, select:focus { border-color: var(--green-700); box-shadow: 0 0 0 4px rgba(31,101,79,.12); }
a { color: var(--green-700); text-underline-offset: 3px; }
a:hover { color: var(--green-950); }
a:focus-visible { outline: 3px solid rgba(31,101,79,.3); outline-offset: 3px; border-radius: 3px; }
.legal-acceptance { display: grid; grid-template-columns: 24px 1fr; align-items: start; gap: 10px; margin: 2px 0 0; }
.legal-acceptance input { width: 22px; min-height: 22px; height: 22px; margin: 1px 0 0; padding: 0; cursor: pointer; }
.legal-acceptance label { margin: 0; line-height: 1.5; cursor: pointer; }
.form-help { margin: 7px 0 16px 34px; color: var(--muted); font-size: .82rem; line-height: 1.45; }
.site-footer { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px 22px; padding: 22px 20px 28px; color: var(--muted); font-size: .84rem; }
.site-footer a { color: inherit; }
.legal-version { color: var(--muted); }
.legal-dialog { width: min(720px, calc(100% - 28px)); max-height: calc(100dvh - 28px); padding: 0; border: 0; border-radius: var(--radius-lg); color: var(--ink); background: var(--surface); box-shadow: 0 24px 70px rgba(12,48,38,.25); }
.legal-dialog::backdrop { background: rgba(12,48,38,.62); backdrop-filter: blur(3px); }
.legal-modal { display: flex; max-height: calc(100dvh - 28px); flex-direction: column; }
.legal-modal-header { display: flex; flex: 0 0 auto; align-items: flex-start; justify-content: space-between; gap: 20px; padding: 24px 26px 18px; border-bottom: 1px solid var(--line); }
.legal-modal-header .eyebrow { margin-bottom: 4px; }
.legal-modal-content { overflow-y: auto; padding: 22px 26px 30px; outline: 0; overscroll-behavior: contain; }
.legal-modal-content h3 { margin: 28px 0 10px; font-size: 1.05rem; }
.legal-modal-content p, .legal-modal-content li { line-height: 1.65; }
.legal-modal-content li + li { margin-top: 6px; }

.button { min-height: 42px; padding: 0 17px; border: 0; border-radius: 11px; font-weight: 700; transition: transform .15s, background .2s, box-shadow .2s; }
.button:hover { transform: translateY(-1px); }
.button:focus-visible { outline: 3px solid rgba(31,101,79,.3); outline-offset: 2px; }
.button-primary { color: #fff; background: var(--green-800); box-shadow: 0 7px 17px rgba(23,76,60,.2); }
.button-primary:hover { background: var(--green-950); }
.button-secondary { color: var(--green-800); background: var(--green-50); }
.button-ghost { color: var(--green-800); background: transparent; }
.button-block { width: 100%; margin-top: 6px; }
.button-save { display: block; min-width: 190px; margin: 22px 0 0 auto; }
.message { min-height: 20px; margin: 12px 0 0; font-size: .88rem; font-weight: 600; }
.message-error { color: var(--danger); }
.message-success { color: var(--green-700); }

.topbar { background: rgba(255,255,255,.9); border-bottom: 1px solid var(--line); backdrop-filter: blur(12px); }
.topbar-content, .page-content { width: min(1080px, calc(100% - 40px)); margin: 0 auto; }
.topbar-content { min-height: 72px; display: flex; align-items: center; justify-content: space-between; }
.user-area { display: flex; align-items: center; gap: 12px; }
.user-greeting { font-size: .9rem; }
.page-content { padding: 58px 0 72px; }
.page-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 30px; margin-bottom: 34px; }
.page-heading .muted { max-width: 620px; margin-bottom: 0; }
.today-pill { flex: 0 0 auto; padding: 10px 14px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: rgba(255,255,255,.55); font-size: .86rem; font-weight: 600; }
.entry-card, .history-card { padding: clamp(22px, 4vw, 36px); border: 1px solid rgba(23,76,60,.07); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow); }
.history-card { margin-top: 26px; }
.section-title-row { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin-bottom: 28px; }
.date-field { max-width: 300px; }
.shift-selector { display: flex; gap: 10px; margin: 0 0 20px; padding: 0; border: 0; }
.shift-selector legend { margin-bottom: 9px; font-size: .9rem; font-weight: 700; }
.shift-selector label { margin: 0; cursor: pointer; }
.shift-selector input { position: absolute; width: 1px; height: 1px; margin: -1px; opacity: 0; }
.shift-selector span { display: block; padding: 10px 16px; border: 1px solid var(--line); border-radius: 999px; background: #fff; }
.shift-selector input:checked + span { color: #fff; border-color: var(--green-800); background: var(--green-800); }
.shift-selector input:focus-visible + span { outline: 3px solid rgba(31,101,79,.3); outline-offset: 2px; }
.readings-grid { display: block; }
.reading-field { max-width: 520px; }
.reading-field.hidden-shift { display: none; }
.reading-field { padding: 22px; border-radius: var(--radius-md); }
.morning-field { background: #fff8e9; border: 1px solid #f7e4b9; }
.night-field { background: #f2f0fb; border: 1px solid #dfdbf2; }
.reading-heading { display: flex; align-items: center; gap: 12px; margin-bottom: 17px; }
.reading-heading label { margin: 0; }
.reading-heading small { display: block; margin-top: 3px; color: var(--muted); }
.reading-icon { font-size: 1.45rem; }
.reading-arrow { color: #9aaaa4; font-size: 1.5rem; }
.input-with-unit { position: relative; }
.input-with-unit input { margin: 0; padding-right: 60px; font-family: "Manrope", sans-serif; font-size: 1.25rem; font-weight: 700; }
.input-with-unit span { position: absolute; top: 50%; right: 15px; transform: translateY(-50%); color: var(--muted); font-size: .84rem; font-weight: 700; }
.photo-field { margin-top: 14px; }
.photo-input { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; opacity: 0; overflow: hidden; }
.photo-button { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; margin: 0; border: 1px dashed rgba(23,76,60,.3); border-radius: 10px; color: var(--green-800); background: rgba(255,255,255,.6); cursor: pointer; transition: border-color .2s, background .2s; }
.photo-button:hover, .photo-input:focus-visible + .photo-button { border-color: var(--green-700); background: #fff; }
.photo-preview { display: grid; grid-template-columns: 48px 1fr auto; align-items: center; gap: 10px; margin-top: 10px; padding: 8px; border-radius: 10px; background: rgba(255,255,255,.75); }
.photo-preview img { width: 48px; height: 48px; border-radius: 8px; object-fit: cover; }
.photo-preview strong, .photo-preview small { display: block; }
.photo-preview strong { font-size: .8rem; }
.photo-preview small { margin-top: 2px; color: var(--muted); font-size: .72rem; }
.remove-photo { width: 30px; height: 30px; padding: 0; border: 0; border-radius: 50%; color: var(--danger); background: transparent; font-size: 1.25rem; }
.photo-links { display: flex; gap: 7px; }
.photo-link { display: inline-flex; align-items: center; gap: 5px; padding: 6px 9px; border-radius: 8px; color: var(--green-800); background: var(--green-50); font-size: .78rem; font-weight: 700; text-decoration: none; }
.photo-link small { color: var(--muted); font-weight: 500; }
.no-photo { color: #9aaaa4; }
.consumption-preview { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-top: 24px; padding: 19px 22px; border-radius: var(--radius-md); color: var(--green-950); background: var(--green-50); }
.preview-label { display: block; font-weight: 800; }
.consumption-preview small { color: var(--muted); }
.consumption-preview strong { font-family: "Manrope", sans-serif; font-size: 2rem; }
.consumption-preview strong small { font-size: .85rem; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 16px 14px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-size: .75rem; letter-spacing: .08em; text-transform: uppercase; }
td { font-size: .92rem; }
td strong { color: var(--green-800); }
tr.past { color: #68756f; }
.actions { display: flex; justify-content: flex-end; gap: 6px; }
.action-button { min-height: 34px; padding: 0 10px; border: 0; border-radius: 8px; color: var(--green-800); background: transparent; font-weight: 700; }
.action-button:hover { background: var(--green-50); }
.action-button.delete { color: var(--danger); }
.pagination { display: flex; justify-content: center; gap: 6px; margin-top: 22px; }
.pagination button { width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 9px; color: var(--ink); background: #fff; }
.pagination button[aria-current="page"] { color: #fff; border-color: var(--green-800); background: var(--green-800); }
.carousel-hint { display: none; }
.empty-state { padding: 35px 20px; text-align: center; color: var(--muted); }
.empty-state > span { font-size: 2rem; }
.empty-state h3 { margin: 10px 0 5px; color: var(--ink); }
.empty-state p { margin-bottom: 0; }
.admin-dialog { width: min(980px, calc(100% - 28px)); max-height: calc(100vh - 28px); padding: 0; border: 0; border-radius: var(--radius-lg); color: var(--ink); background: var(--surface); box-shadow: 0 24px 70px rgba(12,48,38,.25); }
.admin-dialog::backdrop { background: rgba(12,48,38,.55); backdrop-filter: blur(3px); }
.admin-modal { padding: clamp(22px, 4vw, 36px); }
.admin-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; padding-bottom: 22px; border-bottom: 1px solid var(--line); }
.admin-header .muted { margin: 8px 0 0; }
.modal-close { flex: 0 0 auto; width: 40px; height: 40px; padding: 0; border: 0; border-radius: 50%; color: var(--muted); background: var(--green-50); font-size: 1.6rem; line-height: 1; }
.modal-close:hover { color: var(--green-950); background: var(--green-100); }
.admin-dialog section { margin-top: 28px; }
.admin-dialog h3 { margin-bottom: 14px; }
.admin-table-wrap { border: 1px solid var(--line); border-radius: 12px; }
.admin-table-wrap tr:last-child td { border-bottom: 0; }
.admin-section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; }
.admin-section-heading > div { width: min(260px, 100%); }
.admin-section-heading label { font-size: .78rem; }
.admin-section-heading select { min-height: 42px; margin-bottom: 10px; }
.admin-role { display: inline-block; padding: 4px 8px; border-radius: 999px; color: var(--green-800); background: var(--green-50); font-size: .75rem; font-weight: 700; }

@media (max-width: 700px) {
  .topbar-content, .page-content { width: min(100% - 28px, 1080px); }
  .user-greeting { display: none; }
  .page-content { padding-top: 36px; }
  .page-heading { align-items: flex-start; flex-direction: column; gap: 18px; }
  .readings-grid { grid-template-columns: 1fr; gap: 12px; }
  .button-save { width: 100%; }
  .history-heading { align-items: flex-start; flex-direction: column; }
  .history-heading .button { width: 100%; }
  #entries-table, #entries-table tbody, #entries-table tr, #entries-table td { display: block; width: 100%; }
  #entries-table thead { display: none; }
  #entries-table tbody { display: flex; gap: 12px; padding: 2px 28px 10px 0; overflow-x: auto; overscroll-behavior-inline: contain; scroll-behavior: smooth; scroll-snap-type: x mandatory; scrollbar-width: none; touch-action: pan-x pan-y; }
  #entries-table tbody::-webkit-scrollbar { display: none; }
  #entries-table tr { flex: 0 0 calc(100% - 28px); width: calc(100% - 28px); padding: 5px 16px; border: 1px solid var(--line); border-radius: 14px; background: #fff; scroll-snap-align: start; scroll-snap-stop: always; }
  #entries-table td { display: flex; align-items: center; justify-content: space-between; gap: 20px; min-height: 48px; padding: 11px 0; white-space: normal; }
  #entries-table td::before { flex: 0 0 auto; content: attr(data-label); color: var(--muted); font-size: .72rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
  #entries-table td:first-child { width: calc(100% + 32px); margin: -5px -16px 4px; padding: 14px 16px; border-bottom-color: var(--green-100); border-radius: 14px 14px 0 0; color: var(--green-950); background: var(--green-50); font-weight: 800; }
  #entries-table td:first-child::before { color: var(--green-700); }
  #entries-table .photo-links { flex-wrap: wrap; }
  #entries-table .photo-links::before { margin-right: auto; }
  #entries-table .actions { justify-content: flex-end; }
  #entries-table .actions::before { margin-right: auto; }
  #entries-table tr:last-child td:last-child { border-bottom: 0; }
  .carousel-hint { display: flex; align-items: center; gap: 7px; margin: -10px 0 12px; color: var(--muted); font-size: .8rem; font-weight: 600; }
  .carousel-hint span { color: var(--green-700); font-size: 1rem; }
  .table-wrap { overflow-x: visible; }
  .admin-table-wrap { overflow-x: auto; }
  .admin-table-wrap table { min-width: 680px; }
  .pagination { flex-wrap: wrap; gap: 5px; padding-top: 14px; border-top: 1px solid var(--line); }
  .pagination button { min-width: 34px; width: 34px; height: 34px; border-radius: 8px; font-size: .8rem; }
  th, td { padding: 13px 10px; }
  .admin-section-heading { align-items: stretch; flex-direction: column; gap: 4px; }
  .admin-section-heading > div { width: 100%; }
}

@media (max-width: 460px) {
  .topbar-content { min-height: 64px; }
  .brand-icon { width: 32px; height: 32px; }
  .entry-card, .history-card { margin-left: -4px; margin-right: -4px; border-radius: 18px; }
  .section-title-row { align-items: flex-start; }
  .consumption-preview strong { font-size: 1.65rem; }
  .legal-dialog { width: calc(100% - 16px); max-height: calc(100dvh - 16px); border-radius: 18px; }
  .legal-modal { max-height: calc(100dvh - 16px); }
  .legal-modal-header { padding: 20px 18px 15px; }
  .legal-modal-content { padding: 18px 18px 24px; }
}
