/**
 * wunderly – App Layout & Shell
 * Based on wunderly. Design Guide v2.0
 * Mobile-First Responsive
 */

/* ── Reset & Base ────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    overscroll-behavior-y: none;
}

body {
    font-family: var(--font-body);
    font-size: 14px;
    font-weight: 500;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-base);
    min-height: 100vh;
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior-y: none;
    transition: background var(--dur-slow) var(--ease),
                color var(--dur-slow) var(--ease);
}

a {
    color: var(--color-coral);
    text-decoration: none;
}

a:hover {
    color: var(--color-coral-dark);
}

ul, ol {
    list-style: none;
}

img {
    max-width: 100%;
    display: block;
}

/* ── App Shell ───────────────────────────────────── */
.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    max-width: var(--max-width);
    margin: 0 auto;
    position: relative;
    overflow: hidden;
}

/* ── Header ──────────────────────────────────────── */
.header {
    padding: calc(env(safe-area-inset-top, 20px) + 16px) 24px 16px;
    background: var(--bg-base);
    transition: background var(--dur-slow) var(--ease);
    flex-shrink: 0;
}

.header__row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
}

.header__actions {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding-top: 4px;
}

.header--detail .header__actions {
    padding-top: 0;
    gap: 6px;
    flex-shrink: 0;
}

/* Detail Header (List Detail) */
.header--detail {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: calc(env(safe-area-inset-top, 20px) + 16px) 24px 12px;
}

.header__back {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-surface);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 16px;
    flex-shrink: 0;
    transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease), opacity var(--dur-fast) var(--ease);
    position: relative;
}
.header__back::after {
    content: '';
    position: absolute;
    inset: -5px;
}

.header__back:hover {
    border-color: var(--border-hover);
    background: var(--bg-elevated);
}

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

.header__detail-title {
    font-family: var(--font-display);
    font-size: 18px;
    font-weight: 700;
    line-height: 1.25;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header__detail-meta {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Detail Header: Action Buttons (Star, Share, Edit, Delete)
   Visuell 32px, Touch-Target 44px via ::after */
.header__action-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-surface);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    cursor: pointer;
    font-size: 14px;
    flex-shrink: 0;
    transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease), opacity var(--dur-fast) var(--ease);
    -webkit-tap-highlight-color: transparent;
    padding: 0;
    line-height: 1;
}

.header__action-btn::after {
    content: '';
    position: absolute;
    inset: -6px;
}
.header__action-btn:hover {
    border-color: var(--border-hover);
    background: var(--bg-elevated);
}

.header__action-btn:active {
    transform: scale(0.92);
}

.header__action-btn.muted {
    filter: grayscale(1);
    opacity: 0.45;
}

.header__action-btn.active {
    color: var(--color-coral);
    border-color: var(--color-coral);
    background: rgba(255, 107, 64, 0.1);
    filter: none;
    opacity: 1;
}

.header__action-btn.danger:hover {
    color: var(--color-error);
    border-color: var(--color-error);
    background: rgba(220, 38, 38, 0.08);
}

/* ── Main Content ────────────────────────────────── */
.main {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    padding-top: 0;
    /* Platz für: Add-Bar (~62px) + Bottom-Nav (~56px) + safe-area + Puffer */
    padding-bottom: calc(140px + env(safe-area-inset-bottom, 0px));
}

/* When nav is hidden (keyboard open), minimal bottom padding for add-bar only */
.main.nav-hidden {
    padding-bottom: 62px;
}

.main::-webkit-scrollbar {
    display: none;
}

/* ── Bottom Navigation ───────────────────────────── */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 10;
    display: flex;
    justify-content: space-around;
    background: var(--nav-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border);
    padding: 6px 0 calc(8px + env(safe-area-inset-bottom, 16px));
    max-width: var(--max-width);
    margin: 0 auto;
    transition: background var(--dur-slow) var(--ease);
}

/* Nav ausblenden wenn Add-Bar Input fokussiert ist.
   Pure CSS via :has() – kein JS-Timing, kein Race-Condition möglich.
   Fallback: body.keyboard-active wird zusätzlich per JS gesetzt. */
body:has(.add-bar__input:focus) .bottom-nav,
body.keyboard-active .bottom-nav {
    display: none !important;
}

.bottom-nav__item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 44px;
    padding: 6px 16px;
    color: var(--text-muted);
    background: none;
    border: none;
    cursor: pointer;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    transition: color var(--dur-fast) var(--ease);
}

.bottom-nav__item:hover {
    color: var(--color-coral);
    text-decoration: none;
}

.bottom-nav__item.active {
    color: var(--color-coral);
}

.bottom-nav__icon {
    font-size: 20px;
    line-height: 1;
}

.bottom-nav__label {
    font-family: var(--font-body);
    font-size: 10px;
    font-weight: 600;
}

/* ── Auth Layout (Login/Register) ────────────────── */
.auth-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    padding: var(--space-xl);
    padding-top: calc(var(--space-xl) + env(safe-area-inset-top, 0px));
    background: var(--bg-base);
    background-image: radial-gradient(ellipse at 50% 30%, rgba(255,107,64,0.08) 0%, transparent 70%);
}

.auth-page__logo {
    margin-bottom: var(--space-sm);
}

.auth-page__tagline {
    font-family: var(--font-body);
    font-size: 14px;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: var(--space-2xl);
}

.auth-page__card {
    width: 100%;
    max-width: 400px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: var(--space-2xl);
}

.auth-page__footer {
    margin-top: var(--space-xl);
    text-align: center;
    font-size: 13px;
    color: var(--text-secondary);
}

.auth-page__footer a {
    color: var(--color-coral);
    font-weight: 700;
}

.auth-page__divider {
    display: flex;
    align-items: center;
    gap: var(--space-lg);
    margin: var(--space-xl) 0;
    color: var(--text-muted);
    font-size: 12px;
}

.auth-page__divider::before,
.auth-page__divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* ── Section Headers ────────────────────────────── */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    margin-bottom: var(--space-md);
}

.section-label {
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.section-link {
    font-family: var(--font-body);
    font-size: 12px;
    font-weight: 600;
    color: var(--color-coral);
}

/* ── Page Sections ───────────────────────────────── */
.page-title {
    font-family: var(--font-display);
    font-size: 22px;
    font-weight: 700;
    line-height: 1.15;
    letter-spacing: -0.03em;
    color: var(--text-primary);
    margin-bottom: var(--space-lg);
    padding: 0 20px;
}

.page-title .dot {
    color: var(--color-coral);
}

.empty-state {
    text-align: center;
    padding: var(--space-2xl) var(--space-xl);
    color: var(--text-secondary);
}

.empty-state__icon {
    font-size: 3rem;
    margin-bottom: var(--space-lg);
    opacity: 0.5;
}

.empty-state__text {
    font-family: var(--font-display);
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.01em;
    margin-bottom: var(--space-sm);
    color: var(--text-primary);
}

/* ── Loading ─────────────────────────────────────── */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-2xl);
    color: var(--text-muted);
    font-size: 13px;
}

.loading::after {
    content: '';
    display: inline-block;
    width: 18px;
    height: 18px;
    margin-left: var(--space-sm);
    border: 2px solid var(--border);
    border-top-color: var(--color-coral);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ── Toast / Notifications ───────────────────────── */
.toast-container {
    position: fixed;
    top: calc(env(safe-area-inset-top, 20px) + 58px);
    left: 16px;
    right: 16px;
    z-index: 30;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    max-width: var(--max-width);
    margin: 0 auto;
    pointer-events: none;
}

.toast {
    background: var(--toast-bg);
    color: var(--toast-text);
    padding: 11px 16px;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 12.5px;
    box-shadow: var(--shadow-lg);
    pointer-events: auto;
    cursor: pointer;
    animation: toastIn 0.35s var(--ease);
}

.toast--success { border-left: 3px solid var(--color-success); background: #E8F8EB; color: #2D7A3A; }
[data-theme="dark"] .toast--success { background: #1A3D22; color: #8EDFA0; }
.toast--error   { border-left: 3px solid var(--color-error); }
.toast--info    { border-left: 3px solid var(--color-coral); }

@keyframes toastIn {
    from { opacity: 0; transform: translateY(-16px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes toastOut {
    to { opacity: 0; transform: translateY(-16px); }
}

/* ── Animations ──────────────────────────────────── */
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes tileIn {
    from { opacity: 0; transform: scale(0.9); }
    to   { opacity: 1; transform: scale(1); }
}


/* ── Mobile: Prevent zoom on inputs (font-size >= 16px) ── */
@media (max-width: 480px) {
    .form-input,
    .add-bar__input,
    input, select, textarea {
        font-size: 16px;
    }
}

/* ── Touch behavior ─────────────────────────────── */
button, a, input, select, textarea {
    touch-action: manipulation;
}

/* ── Utility ─────────────────────────────────────── */
.hidden {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}
