:root {
    --bg: #f7f8f6;
    --surface: #ffffff;
    --text: #17221f;
    --muted: #68736f;
    --line: #dfe5e2;
    --primary: #176b57;
    --primary-dark: #0f5141;
    --primary-soft: #e4f1ed;
    --accent: #b14d3d;
    --danger-soft: #faece9;
    --shadow: 0 8px 28px rgba(23, 34, 31, 0.07);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--bg);
    font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body { margin: 0; min-height: 100vh; background: var(--bg); }
button, input { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: var(--primary); text-underline-offset: 3px; }
[hidden] { display: none !important; }

.app-header {
    height: 64px;
    padding: env(safe-area-inset-top) max(20px, env(safe-area-inset-right)) 0 max(20px, env(safe-area-inset-left));
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(223, 229, 226, 0.8);
    background: rgba(247, 248, 246, 0.96);
}

.brand { display: inline-flex; align-items: center; gap: 9px; color: var(--text); font-weight: 750; font-size: 18px; text-decoration: none; }
.brand-mark { width: 28px; height: 28px; display: grid; place-items: center; color: white; background: var(--primary); border-radius: 7px; font-size: 17px; }
.desktop-logout { display: none; }
.app-main { width: min(100%, 760px); margin: 0 auto; padding: 30px 18px 112px; }

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(28px, 8vw, 38px); line-height: 1.15; letter-spacing: 0; }
h2 { font-size: 18px; letter-spacing: 0; }
.eyebrow { margin-bottom: 7px; color: var(--primary); font-size: 12px; line-height: 1; font-weight: 800; text-transform: uppercase; letter-spacing: 0; }
.page-heading { margin-bottom: 24px; }

.date-nav { height: 48px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; margin-bottom: 24px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.date-nav a, .date-nav .disabled { display: flex; align-items: center; gap: 5px; min-height: 46px; color: var(--muted); font-size: 14px; font-weight: 650; text-decoration: none; }
.date-nav a:last-child, .date-nav .disabled:last-child { justify-content: flex-end; }
.date-nav a span, .date-nav .disabled span { font-size: 23px; font-weight: 400; }
.date-nav .date-nav-today { color: var(--primary); padding: 0 14px; }
.date-nav .disabled { color: #b6bfbc; }

.habit-day-list { display: grid; gap: 10px; }
.habit-day-item { overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); transition: border-color 160ms ease, background-color 160ms ease; }
.habit-day-item.completed { border-color: #b9d8cf; background: #fbfefd; }
.habit-toggle { min-height: 68px; padding: 11px 14px; display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; align-items: center; gap: 12px; cursor: pointer; }
.habit-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.custom-check { width: 36px; height: 36px; display: grid; place-items: center; border: 2px solid #aeb9b5; border-radius: 8px; color: transparent; background: var(--surface); font-size: 21px; font-weight: 800; transition: 150ms ease; }
.habit-toggle input:checked + .custom-check { border-color: var(--primary); color: white; background: var(--primary); }
.habit-toggle input:focus-visible + .custom-check { outline: 3px solid rgba(23, 107, 87, 0.24); outline-offset: 2px; }
.habit-name { min-width: 0; overflow-wrap: anywhere; font-size: 17px; font-weight: 700; }
.save-indicator { color: var(--muted); font-size: 11px; }
.habit-note-wrap { padding: 0 14px 14px 66px; }
.habit-note { width: 100%; height: 42px; padding: 0 0 7px; border: 0; border-bottom: 1px solid #bfd3cd; border-radius: 0; color: var(--text); background: transparent; outline: none; }
.habit-note:focus { border-color: var(--primary); }
.habit-note::placeholder { color: #919c98; }

.empty-state { padding: 48px 26px; text-align: center; border: 1px dashed #cbd5d1; border-radius: 8px; background: rgba(255,255,255,.55); }
.empty-state.compact { padding: 34px 20px; }
.empty-state h2 { margin: 12px 0 8px; }
.empty-state p { color: var(--muted); line-height: 1.5; }
.empty-check { width: 46px; height: 46px; display: grid; place-items: center; margin: 0 auto; border-radius: 8px; color: var(--primary); background: var(--primary-soft); font-size: 26px; }

.week-table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px 8px; scrollbar-width: thin; }
.week-table { width: 100%; min-width: 610px; border-collapse: separate; border-spacing: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.week-table th, .week-table td { height: 52px; padding: 8px; border-bottom: 1px solid var(--line); text-align: center; }
.week-table tr:last-child th, .week-table tr:last-child td { border-bottom: 0; }
.week-table thead th { height: 58px; color: var(--muted); background: #f0f3f1; font-size: 12px; }
.week-table thead th span, .week-table thead th small { display: block; }
.week-table thead th small { margin-top: 3px; font-size: 12px; font-weight: 500; }
.week-table thead th.today { color: var(--primary); background: var(--primary-soft); }
.week-table th:first-child { position: sticky; left: 0; z-index: 1; width: 142px; max-width: 142px; text-align: left; background: var(--surface); overflow-wrap: anywhere; }
.week-table thead th:first-child { z-index: 2; background: #f0f3f1; }
.week-table tbody th { font-size: 13px; }
.week-table td.future { background: #fafbfa; }
.week-table td.not-active { color: #c0c8c5; background: #f7f8f7; }
.week-check { width: 26px; height: 26px; display: grid; place-items: center; margin: auto; border-radius: 7px; color: white; background: var(--primary); font-size: 15px; font-weight: 800; }
.week-summary { margin-top: 28px; }
.week-summary ul { padding: 0; margin: 0; list-style: none; border-top: 1px solid var(--line); }
.week-summary li { min-height: 48px; display: flex; align-items: center; justify-content: space-between; gap: 15px; border-bottom: 1px solid var(--line); }
.week-summary li span { overflow-wrap: anywhere; }
.week-summary strong { color: var(--primary); }

.management-section { margin-bottom: 38px; }
.management-section > h2 { margin-bottom: 16px; }
.form-stack { display: grid; gap: 16px; }
.form-stack label { display: grid; gap: 7px; color: #34413d; font-size: 13px; font-weight: 700; }
input[type="email"], input[type="password"], input[type="text"], input[type="date"] { min-width: 0; width: 100%; height: 48px; padding: 0 13px; border: 1px solid #cbd4d1; border-radius: 7px; color: var(--text); background: var(--surface); outline: none; }
input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(23,107,87,.13); }
.primary-button, .secondary-button, .small-button { min-height: 46px; display: inline-flex; align-items: center; justify-content: center; padding: 0 18px; border: 0; border-radius: 7px; font-weight: 750; text-decoration: none; cursor: pointer; }
.primary-button { color: white; background: var(--primary); }
.primary-button:hover { background: var(--primary-dark); }
.secondary-button { color: var(--primary); background: var(--primary-soft); }
.small-button { min-height: 40px; color: white; background: var(--primary); }
button:disabled { opacity: .55; cursor: wait; }
.section-title-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.section-title-row h2 { margin: 0; }
.section-title-row span { min-width: 26px; height: 26px; display: grid; place-items: center; border-radius: 50%; color: var(--muted); background: #e9edeb; font-size: 12px; font-weight: 750; }
.habit-admin-list { border-top: 1px solid var(--line); }
.habit-admin-item { min-height: 70px; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.habit-admin-info { min-width: 0; }
.habit-admin-info strong, .habit-admin-info span { display: block; overflow-wrap: anywhere; }
.habit-admin-info strong { margin-bottom: 4px; }
.habit-admin-info span { color: var(--muted); font-size: 12px; }
.habit-admin-actions { display: flex; gap: 6px; }
.icon-button { width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 7px; color: var(--muted); background: var(--surface); font-size: 20px; cursor: pointer; }
.icon-button.danger { color: var(--accent); background: var(--danger-soft); }
.rename-form { grid-column: 1 / -1; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.rename-form .text-button { grid-column: 1 / -1; justify-self: start; }
.text-button { min-height: 36px; padding: 0; border: 0; color: var(--primary); background: transparent; font-weight: 700; cursor: pointer; }
.empty-list { padding: 18px 0; color: var(--muted); }

.auth-body .app-header { border: 0; }
.auth-body .app-main { min-height: calc(100vh - 64px); display: grid; align-items: center; padding-top: 28px; padding-bottom: 50px; }
.auth-panel { width: min(100%, 410px); margin: 0 auto; }
.auth-heading { margin-bottom: 30px; }
.auth-heading h1 { margin-bottom: 10px; }
.auth-heading > p:last-child { color: var(--muted); line-height: 1.5; }
.auth-panel .primary-button { margin-top: 4px; }
.auth-switch { margin-top: 24px; color: var(--muted); text-align: center; font-size: 14px; }
.label-hint { color: var(--muted); font-size: 11px; font-weight: 500; }
.message { margin-bottom: 18px; padding: 12px 14px; border-radius: 7px; font-size: 14px; }
.message.error { color: #843427; background: var(--danger-soft); }

.bottom-nav { position: fixed; z-index: 10; left: 0; right: 0; bottom: 0; height: calc(70px + env(safe-area-inset-bottom)); display: grid; grid-template-columns: repeat(4, 1fr); padding: 0 max(8px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(8px, env(safe-area-inset-left)); border-top: 1px solid var(--line); background: rgba(255,255,255,.97); box-shadow: 0 -8px 30px rgba(23,34,31,.05); }
.bottom-nav a, .bottom-nav button { width: 100%; height: 69px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px; padding: 0; border: 0; color: #77817e; background: transparent; font-size: 10px; font-weight: 700; text-decoration: none; cursor: pointer; }
.bottom-nav a.active { color: var(--primary); }
.nav-icon { width: 21px; height: 21px; position: relative; display: block; }
.nav-icon-calendar { border: 2px solid currentColor; border-radius: 4px; }
.nav-icon-calendar::before { content: ''; position: absolute; left: 2px; right: 2px; top: 5px; border-top: 2px solid currentColor; }
.nav-icon-calendar::after { content: ''; position: absolute; left: 4px; top: -4px; width: 7px; height: 4px; border-left: 2px solid currentColor; border-right: 2px solid currentColor; }
.nav-icon-grid { border: 2px solid currentColor; border-radius: 3px; box-shadow: inset 0 6px 0 transparent; }
.nav-icon-grid::before, .nav-icon-grid::after { content: ''; position: absolute; background: currentColor; }
.nav-icon-grid::before { top: 5px; bottom: 5px; left: 8px; width: 2px; }
.nav-icon-grid::after { left: 3px; right: 3px; top: 8px; height: 2px; }
.nav-icon-list::before { content: '✓'; position: absolute; left: 0; top: -3px; font-size: 20px; font-weight: 800; }
.nav-icon-list::after { content: ''; position: absolute; left: 9px; right: 0; top: 5px; height: 2px; background: currentColor; box-shadow: 0 7px 0 currentColor; }
.nav-icon-logout { border: 2px solid currentColor; border-right: 0; border-radius: 3px 0 0 3px; width: 14px; }
.nav-icon-logout::after { content: '›'; position: absolute; left: 9px; top: -7px; font-size: 25px; }
.toast { position: fixed; z-index: 30; left: 16px; right: 16px; bottom: calc(82px + env(safe-area-inset-bottom)); max-width: 500px; margin: auto; padding: 12px 15px; border-radius: 7px; color: white; background: #2b3733; box-shadow: var(--shadow); opacity: 0; transform: translateY(10px); pointer-events: none; transition: 180ms ease; font-size: 14px; }
.toast.visible { opacity: 1; transform: translateY(0); }
.toast.error { background: #873b30; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (min-width: 700px) {
    .app-header { height: 72px; padding-left: 32px; padding-right: 32px; }
    .desktop-logout { display: block; }
    .app-main { padding: 46px 24px 118px; }
    .habit-toggle { min-height: 72px; padding-left: 18px; padding-right: 18px; }
    .habit-note-wrap { padding-left: 70px; padding-right: 18px; }
    .week-table-wrap { margin: 0; padding-left: 0; padding-right: 0; }
    .auth-body .app-main { padding-top: 36px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
