:root {
    --bg: #f3f7f4;
    --surface: #ffffff;
    --text: #14261a;
    --text-muted: #5b6b60;
    --primary: #2f7d4a;
    --primary-hover: #24633a;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --border: #c5d0c8;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.15);
    --radius: 12px;
    --radius-sm: 8px;
    --nav-height: 64px;
    --topbar-height: 96px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-display: "Shrikhand", cursive;
}

*, *::before, *::after {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.app-body {
    min-height: 100dvh;
}

.app-main {
    max-width: 640px;
    margin: 0 auto;
    padding: 16px 16px calc(var(--nav-height) + var(--safe-bottom) + 16px);
}

.app-body.has-fixed-topbar .app-main {
    padding-top: calc(var(--topbar-height) + 14px);
}

.app-topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding-top: var(--safe-top);
    width: 100%;
    max-width: 640px;
    margin: 0 auto;
}

.app-topbar-inner {
    padding: 6px 12px 0;
}

.page-header-row.page-header-topbar {
    margin-bottom: 10px;
    align-items: center;
}

.page-header-row.page-header-topbar .header-controls {
    margin-top: 0;
}

.page-header-topbar .calendar-id {
    display: flex;
    align-items: center;
    font-family: var(--font-display);
    font-size: 1.9rem;
    font-weight: 400;
    letter-spacing: 0.01em;
    line-height: 1;
    text-transform: none;
    padding-top: 0.14em;
}

.period-selector-topbar {
    margin: 0;
    border-radius: 8px;
    box-shadow: none;
    height: 36px;
    min-height: 36px;
}

.period-selector-topbar .period-btn {
    padding: 0 4px;
    height: 100%;
    min-height: 0;
    font-size: 0.75rem;
    line-height: 1.1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-body {
    min-height: 100dvh;
}

.login-page {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 100dvh;
    padding: 24px;
    padding-top: calc(56px + env(safe-area-inset-top, 0px));
    background: linear-gradient(160deg, #0f2e1c 0%, #2f7d4a 100%);
}

.login-lang-corner {
    position: absolute;
    top: calc(16px + env(safe-area-inset-top, 0px));
    right: calc(16px + env(safe-area-inset-right, 0px));
    z-index: 10;
}

.login-lang-corner .lang-toggle {
    border-color: rgba(255, 255, 255, 0.35);
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.login-lang-corner .lang-toggle-btn + .lang-toggle-btn {
    border-left-color: rgba(255, 255, 255, 0.35);
}

.login-lang-corner .lang-toggle-btn.active {
    background: rgba(255, 255, 255, 0.28);
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.6);
}

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

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 32px 28px;
    box-shadow: var(--shadow-lg);
}

.login-title {
    margin: 0 0 8px;
    text-align: center;
}

.login-subtitle {
    margin: 0 0 28px;
    text-align: center;
    color: var(--text-muted);
    font-size: 1rem;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.lang-toggle {
    display: flex;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    background: var(--surface);
    box-shadow: var(--shadow);
}

/* Flip LANGUAGE_SELECTOR_ENABLED in i18n.js to true to show again. */
html.lang-selector-hidden .lang-toggle,
html.lang-selector-hidden .login-lang-corner {
    display: none !important;
}

.login-alt-link {
    margin: 20px 0 0;
    text-align: center;
    font-size: 0.9375rem;
}

.login-alt-link a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
}

.login-alt-link a:hover {
    text-decoration: underline;
}

.lang-toggle-btn {
    padding: 6px 8px;
    border: none;
    background: transparent;
    cursor: pointer;
    touch-action: manipulation;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
}

.lang-toggle-btn + .lang-toggle-btn {
    border-left: 1px solid var(--border);
}

.lang-toggle-btn.active {
    background: #e8f2eb;
    box-shadow: inset 0 0 0 2px var(--primary);
}

.lang-toggle-btn .flag-icon {
    width: 22px;
    height: 15px;
    border-radius: 2px;
    display: block;
}

.app-title {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.app-title.login-title {
    font-family: var(--font-display);
    font-size: clamp(1.75rem, 7vw, 2.25rem);
    font-weight: 400;
    letter-spacing: 0.01em;
    color: var(--text);
    line-height: 1.15;
}

.login-form .form-group {
    margin-bottom: 16px;
}

.form-input {
    width: 100%;
    padding: 14px 16px;
    font-size: 1.125rem;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    transition: border-color 0.15s;
    -webkit-appearance: none;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
}

.form-color {
    width: 100%;
    height: 48px;
    padding: 4px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    background: var(--surface);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-muted);
}

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

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 14px 24px;
    font-size: 1rem;
    font-weight: 600;
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    min-height: 48px;
    touch-action: manipulation;
}

.btn:active {
    transform: scale(0.98);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

.btn-primary:not(:disabled):hover {
    background: var(--primary-hover);
}

.btn-danger {
    background: var(--danger);
    border-color: #b91c1c;
    color: #fff;
}

.btn-danger:not(:disabled):hover {
    background: var(--danger-hover);
}

.btn-ghost {
    background: transparent;
    border-color: var(--border);
    color: var(--text-muted);
}

.btn-block {
    width: 100%;
}

.page-header {
    margin-bottom: 16px;
}

.page-header-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.page-header-row > h1,
.page-header-row > .calendar-id {
    margin: 0;
    min-width: 0;
}

.page-header-row .header-controls {
    margin-top: 2px;
}

.page-header h1 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
}

.view-toggle {
    display: flex;
    flex-shrink: 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    background: var(--surface);
}

.view-toggle-btn {
    padding: 8px 10px;
    font-size: 0.75rem;
    font-weight: 600;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    touch-action: manipulation;
    display: flex;
    align-items: center;
    justify-content: center;
}

.view-toggle-btn .view-icon {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.view-toggle-btn + .view-toggle-btn {
    border-left: 1px solid var(--border);
}

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

.calendar-id {
    text-transform: lowercase;
}

.page-subtitle {
    margin: 4px 0 0;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.period-selector {
    display: flex;
    width: 100%;
    margin-bottom: 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.period-btn {
    flex: 1 1 0;
    min-width: 0;
    padding: 10px 6px;
    font-size: clamp(0.6875rem, 2.6vw, 0.8125rem);
    font-weight: 600;
    border: none;
    border-right: 1px solid var(--border);
    border-radius: 0;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    white-space: normal;
    line-height: 1.2;
    text-wrap: balance;
    word-break: normal;
    overflow-wrap: break-word;
    transition: background 0.15s, color 0.15s;
    touch-action: manipulation;
}

.period-btn:last-child {
    border-right: none;
}

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

.calendar-container {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.loading-state,
.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 40px 16px;
}

.week-block {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.week-header {
    padding: 16px 16px 14px;
    font-weight: 600;
    font-size: 1.125rem;
    letter-spacing: -0.02em;
    color: var(--text);
    background: #eaf3ed;
    border-bottom: 1px solid var(--border);
}

.days-grid {
    display: flex;
    flex-direction: column;
}

.day-cell {
    position: relative;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.1s, box-shadow 0.1s;
    touch-action: manipulation;
}

.day-cell:last-child {
    border-bottom: none;
}

.day-cell:active {
    background: #f3f4f6;
}

.day-cell.today {
    background: #e2eee6;
    box-shadow: inset 0 0 0 2px var(--primary);
    z-index: 1;
}

.day-cell.today:active {
    background: #d3e5d9;
}

.day-cell.past {
    background: #f0f1f2;
}

.day-cell.past:active {
    background: #e8e9eb;
}

.day-cell.weekend:not(.today) {
    background: #fdf2f4;
}

.day-cell.weekend:not(.today):active {
    background: #f8e6ea;
}

.day-cell.weekend.past:not(.today) {
    background: #f3eaec;
}

.day-cell.weekend.past:not(.today):active {
    background: #ebe0e3;
}

.day-cell.past .day-name,
.day-cell.past .day-date {
    color: #9aa3ab;
    font-weight: 400;
}

.day-cell.past .day-items {
    opacity: 0.48;
    filter: grayscale(0.4) saturate(0.55) brightness(1.08);
}

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

.day-cell:has(.day-items:not(:empty)) .day-header {
    margin-bottom: 8px;
}

.day-name {
    font-weight: 700;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.day-date {
    font-size: 0.875rem;
    color: var(--text-muted);
    flex-shrink: 0;
}

.day-items {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
}

.day-items:empty {
    display: none;
}

.calendar-item {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    padding: 2px 0;
}

.calendar-item .pill {
    cursor: pointer;
}

.pill {
    display: inline-block;
    width: fit-content;
    max-width: 100%;
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 0.8125rem;
    font-weight: 600;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pill-person {
    border: none;
}

.pill-event {
    background: #fff;
    border: 2px solid;
}

.bottom-sheet {
    position: fixed;
    inset: 0;
    z-index: 1000;
    pointer-events: none;
    visibility: hidden;
}

.bottom-sheet.open {
    pointer-events: auto;
    visibility: visible;
}

.bottom-sheet-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    opacity: 0;
    transition: opacity 0.25s;
}

.bottom-sheet.open .bottom-sheet-backdrop {
    opacity: 1;
}

.bottom-sheet-panel {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 85dvh;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: 20px 20px 0 0;
    padding: 12px 20px calc(20px + var(--safe-bottom));
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
    box-shadow: var(--shadow-lg);
}

.bottom-sheet.open .bottom-sheet-panel {
    transform: translateY(0);
}

.bottom-sheet-handle {
    width: 36px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 0 auto 16px;
}

.sheet-title {
    margin: 0 0 4px;
    font-size: 1.25rem;
}

.sheet-date {
    margin: 0 0 20px;
    color: var(--text-muted);
    font-size: 0.9375rem;
}

.sheet-section {
    margin-bottom: 20px;
}

.sheet-label {
    margin: 0 0 10px;
    font-size: 0.8125rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

.option-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    padding: 6px 4px 4px 0;
}

.option-btn {
    position: relative;
    padding: 12px 18px;
    font-size: 0.9375rem;
    font-weight: 600;
    border-radius: 999px;
    border: 2px solid transparent;
    cursor: pointer;
    min-height: 44px;
    touch-action: manipulation;
    transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s, filter 0.15s, outline 0.15s;
    opacity: 0.4;
    filter: grayscale(0.35);
}

.option-btn:active {
    transform: scale(0.97);
}

.option-btn.selected {
    opacity: 1;
    filter: none;
    transform: scale(1.04);
    box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--primary);
    outline: none;
    z-index: 1;
}

.option-btn.selected::after {
    content: "✓";
    position: absolute;
    top: -6px;
    right: -6px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
    line-height: 1;
}

.option-btn-person {
    border: none;
}

.option-btn-event {
    background: #fff;
    border-width: 2px;
    border-style: solid;
}

.option-btn-event.selected {
    background: color-mix(in srgb, currentColor 12%, #fff);
    border-width: 3px;
}

.sheet-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}

.confirm-dialog {
    position: fixed;
    inset: 0;
    z-index: 1100;
    pointer-events: none;
    visibility: hidden;
}

.confirm-dialog.open {
    pointer-events: auto;
    visibility: visible;
}

.confirm-dialog-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    opacity: 0;
    transition: opacity 0.2s;
}

.confirm-dialog.open .confirm-dialog-backdrop {
    opacity: 1;
}

.confirm-dialog-panel {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) scale(0.95);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    width: calc(100% - 48px);
    max-width: 320px;
    box-shadow: var(--shadow-lg);
    transition: transform 0.2s;
}

.confirm-dialog.open .confirm-dialog-panel {
    transform: translate(-50%, -50%) scale(1);
}

.confirm-dialog-panel h3 {
    margin: 0 0 8px;
}

.confirm-dialog-panel p {
    margin: 0 0 20px;
    color: var(--text-muted);
}

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

.confirm-actions .btn {
    flex: 1;
}

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding-bottom: var(--safe-bottom);
    z-index: 100;
    max-width: 640px;
    margin: 0 auto;
}

.form-input.is-invalid {
    border-color: var(--danger);
}

.form-warning {
    color: var(--danger);
    font-size: 0.8125rem;
    margin: 8px 0 0;
    line-height: 1.35;
}

.form-hint {
    margin: 0 0 8px;
    font-size: 0.8125rem;
    color: var(--text-muted);
    line-height: 1.35;
}

.form-success {
    color: #15803d;
    font-size: 0.875rem;
    margin: 0 0 12px;
}

.form-input-pin {
    letter-spacing: normal;
    text-align: left;
    font-variant-numeric: tabular-nums;
}

.settings-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px 18px;
}

.settings-section-title {
    margin: 0 0 16px;
    font-size: 1.125rem;
    font-weight: 700;
}

.bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 8px 2px;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.625rem;
    font-weight: 600;
    min-height: var(--nav-height);
    touch-action: manipulation;
}

.bottom-nav-item svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

.bottom-nav-item.active {
    color: var(--primary);
}

.config-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.config-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    cursor: pointer;
    touch-action: manipulation;
    transition: background 0.1s;
}

.config-card:active {
    background: #f3f4f6;
}

.config-card-info {
    flex: 1;
    min-width: 0;
}

.config-card-name {
    font-weight: 600;
    font-size: 1rem;
}

.config-card-preview {
    margin-top: 6px;
}

.sort-controls {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex-shrink: 0;
}

.sort-btn {
    width: 36px;
    height: 32px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #f8f9fc;
    color: var(--text-muted);
    font-size: 0.6875rem;
    line-height: 1;
    cursor: pointer;
    touch-action: manipulation;
}

.sort-btn:active:not(:disabled) {
    background: #e8f2eb;
    color: var(--text);
}

.sort-btn:disabled {
    opacity: 0.35;
    cursor: default;
}

.fab {
    position: fixed;
    right: 20px;
    bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-size: 1.75rem;
    font-weight: 300;
    border: 1px solid #1f5c36;
    box-shadow: 0 4px 16px rgba(47, 125, 74, 0.4);
    cursor: pointer;
    z-index: 50;
    touch-action: manipulation;
    line-height: 1;
}

.fab:active {
    transform: scale(0.95);
}

.person-preview,
.event-preview {
    margin: 16px 0;
}

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

/* Compact view: always one row of days */
.app-body.view-compact .days-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
}

.app-body.view-compact .day-cell {
    border-bottom: none;
    border-right: 1px solid var(--border);
    min-height: 0;
    padding: 6px 4px;
}

.app-body.view-compact .day-cell:nth-child(7n) {
    border-right: none;
}

.app-body.view-compact .day-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0;
    margin-bottom: 0;
}

.app-body.view-compact .day-cell:has(.day-items:not(:empty)) .day-header {
    margin-bottom: 4px;
}

.app-body.view-compact .day-name {
    font-size: 0.625rem;
    letter-spacing: 0.02em;
}

.app-body.view-compact .day-date {
    font-size: 0.6875rem;
}

.app-body.view-compact .day-items {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
}

.app-body.view-compact .day-persons,
.app-body.view-compact .day-events {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px;
}

.app-body.view-compact .day-persons:empty,
.app-body.view-compact .day-events:empty {
    display: none;
}

.app-body.view-compact .pill {
    font-size: 0.625rem;
    padding: 2px 5px;
    border-radius: 4px;
    min-width: 1.25rem;
    text-align: center;
}

.app-body.view-compact .pill-event {
    border-width: 1px;
}

.app-body.view-compact .week-header {
    padding: 12px 10px;
    font-size: 1rem;
    font-weight: 600;
}

@media (min-width: 768px) {
    .app-body:not(.view-compact) .days-grid {
        display: grid;
        grid-template-columns: repeat(7, 1fr);
    }

    .app-body:not(.view-compact) .day-cell {
        border-bottom: none;
        border-right: 1px solid var(--border);
        min-height: 0;
        padding: 10px;
    }

    .app-body:not(.view-compact) .day-cell:nth-child(7n) {
        border-right: none;
    }

    .app-body:not(.view-compact) .day-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 2px;
    }

    .app-body:not(.view-compact) .day-name {
        font-size: 0.75rem;
    }

    .app-body:not(.view-compact) .day-date {
        font-size: 0.75rem;
    }

    .app-body:not(.view-compact) .pill {
        font-size: 0.75rem;
        padding: 4px 8px;
    }
}
