/* ---------- Design tokens ---------- */
:root {
    --color-bg: #F6F7FB;
    --color-surface: #FFFFFF;
    --color-border: #E5E7EB;
    --color-text: #1C1C1E;
    --color-text-secondary: #6B7280;
    --color-text-tertiary: #9CA3AF;

    --color-primary: #4F46E5;
    --color-primary-hover: #4338CA;
    --color-primary-contrast: #FFFFFF;

    --color-danger: #DC2626;
    --color-danger-bg: #FDECEC;

    /* Statuts */
    --status-to_visit-bg: #E8EEFE;
    --status-to_visit-fg: #3452C7;
    --status-card_left-bg: #FEF3E2;
    --status-card_left-fg: #B45309;
    --status-thinking-bg: #F3E8FF;
    --status-thinking-fg: #7E22CE;
    --status-accepted-bg: #E4F8EC;
    --status-accepted-fg: #15803D;
    --status-refused-bg: #FDE8E8;
    --status-refused-fg: #B91C1C;
    --status-callback-bg: #E0F7FA;
    --status-callback-fg: #0E7490;
    --status-closed-bg: #E9E9EC;
    --status-closed-fg: #52525B;

    --urgent-today: #DC2626;
    --urgent-overdue: #EA580C;
    --urgent-visit: #3452C7;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;

    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;

    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
    --shadow-md: 0 4px 16px rgba(16, 24, 40, 0.10);
    --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.18);

    --duration-fast: 150ms;
    --duration-base: 220ms;
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);

    color-scheme: light;
}

/* ---------- Reset ---------- */
* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
}

body {
    background: var(--color-bg);
    color: var(--color-text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
    padding-bottom: 96px;
}

h1, h2, h3 {
    margin: 0;
}

button {
    font-family: inherit;
}

input, select, textarea, button {
    font-size: 16px;
}

a {
    color: inherit;
}

svg.icon {
    width: 1em;
    height: 1em;
}

/* ---------- Layout ---------- */
.topbar {
    padding: var(--space-5) var(--space-4) var(--space-3);
    max-width: 720px;
    margin: 0 auto;
}

.topbar h1 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.container {
    max-width: 720px;
    margin: 0 auto;
    padding: 0 var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
}

.section-title {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-secondary);
    margin: 0 0 var(--space-2);
}

.banner {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    font-size: 14px;
}

.banner-error {
    background: var(--color-danger-bg);
    color: var(--color-danger);
}

/* ---------- Stats ---------- */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
    gap: var(--space-2);
}

.stat-tile {
    background: var(--color-surface);
    border-radius: var(--radius-md);
    padding: var(--space-3);
    box-shadow: var(--shadow-sm);
    text-align: center;
}

.stat-tile .stat-value {
    font-size: 22px;
    font-weight: 700;
    line-height: 1.2;
}

.stat-tile .stat-label {
    font-size: 12px;
    color: var(--color-text-secondary);
    margin-top: 2px;
}

/* ---------- Today block ---------- */
.today-block:empty,
.today-block.is-empty {
    display: none;
}

.today-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.today-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    background: var(--color-surface);
    border-radius: var(--radius-md);
    padding: var(--space-3) var(--space-4);
    box-shadow: var(--shadow-sm);
    border-left: 4px solid transparent;
    cursor: pointer;
    text-align: left;
    width: 100%;
    border-top: none;
    border-right: none;
    border-bottom: none;
    appearance: none;
    background-color: var(--color-surface);
}

.today-item.urgency-today { border-left-color: var(--urgent-today); }
.today-item.urgency-overdue { border-left-color: var(--urgent-overdue); }
.today-item.urgency-visit { border-left-color: var(--urgent-visit); }

.today-item .dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.urgency-today .dot { background: var(--urgent-today); }
.urgency-overdue .dot { background: var(--urgent-overdue); }
.urgency-visit .dot { background: var(--urgent-visit); }

.today-item-body {
    min-width: 0;
    flex: 1;
}

.today-item-name {
    font-weight: 600;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.today-item-meta {
    font-size: 13px;
    color: var(--color-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ---------- Toolbar ---------- */
.toolbar {
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
}

.search-wrap {
    position: relative;
    flex: 1 1 220px;
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-text-tertiary);
    pointer-events: none;
}

#searchInput {
    width: 100%;
    height: 44px;
    padding: 0 var(--space-3) 0 40px;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text);
}

#statusFilter {
    height: 44px;
    padding: 0 var(--space-3);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text);
    flex: 0 0 auto;
    max-width: 100%;
}

#searchInput:focus,
#statusFilter:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: 1px;
}

/* ---------- Shop list ---------- */
.shop-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.shop-card {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    background: var(--color-surface);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    text-align: left;
    border: none;
    width: 100%;
    transition: transform var(--duration-fast) var(--ease-out), box-shadow var(--duration-fast) var(--ease-out);
}

.shop-card:active {
    transform: scale(0.98);
}

.shop-card-body {
    min-width: 0;
    flex: 1;
}

.shop-card-top {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: 4px;
}

.shop-card-name {
    font-weight: 600;
    font-size: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.shop-card-address {
    font-size: 13px;
    color: var(--color-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.shop-card-next {
    font-size: 12px;
    color: var(--color-text-tertiary);
    margin-top: 2px;
}

.chevron {
    flex-shrink: 0;
    color: var(--color-text-tertiary);
}

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

/* ---------- Badge ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    font-weight: 600;
    padding: 3px 9px;
    border-radius: 999px;
    white-space: nowrap;
    flex-shrink: 0;
}

.badge::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

.badge-to_visit { background: var(--status-to_visit-bg); color: var(--status-to_visit-fg); }
.badge-card_left { background: var(--status-card_left-bg); color: var(--status-card_left-fg); }
.badge-thinking { background: var(--status-thinking-bg); color: var(--status-thinking-fg); }
.badge-accepted { background: var(--status-accepted-bg); color: var(--status-accepted-fg); }
.badge-refused { background: var(--status-refused-bg); color: var(--status-refused-fg); }
.badge-callback { background: var(--status-callback-bg); color: var(--status-callback-fg); }
.badge-closed { background: var(--status-closed-bg); color: var(--status-closed-fg); }

/* ---------- FAB ---------- */
.fab {
    position: fixed;
    right: var(--space-4);
    bottom: calc(var(--space-4) + env(safe-area-inset-bottom, 0px));
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--color-primary);
    color: var(--color-primary-contrast);
    border: none;
    border-radius: 999px;
    padding: 14px 20px;
    font-size: 15px;
    font-weight: 700;
    box-shadow: var(--shadow-lg);
    cursor: pointer;
    z-index: 30;
    min-height: 48px;
}

.fab:active {
    background: var(--color-primary-hover);
}

.fab svg {
    width: 20px;
    height: 20px;
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 48px;
    padding: 0 var(--space-4);
    border-radius: var(--radius-md);
    font-size: 15px;
    font-weight: 600;
    border: none;
    cursor: pointer;
}

.btn svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

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

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

.btn-secondary {
    background: var(--color-bg);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

.btn-block {
    width: 100%;
}

.btn-danger {
    background: var(--color-danger-bg);
    color: var(--color-danger);
}

.icon-btn {
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 50%;
    color: var(--color-text-secondary);
    cursor: pointer;
    flex-shrink: 0;
}

.icon-btn:active {
    background: var(--color-bg);
}

.icon-btn svg {
    width: 20px;
    height: 20px;
}

/* ---------- Quick action buttons (detail sheet) ---------- */
.quick-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: var(--space-2);
    margin-top: var(--space-2);
}

.quick-actions .btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.quick-actions svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* ---------- Modals ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(17, 17, 22, 0.5);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 50;
    padding: 0;
    animation: overlay-in var(--duration-base) var(--ease-out);
}

.modal-overlay[hidden] {
    display: none;
}

.modal {
    background: var(--color-surface);
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    animation: sheet-in var(--duration-base) var(--ease-out);
}

@media (min-width: 640px) {
    .modal-overlay {
        align-items: center;
        padding: var(--space-4);
    }
    .modal {
        border-radius: var(--radius-lg);
        max-height: 85vh;
    }
}

@keyframes overlay-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes sheet-in {
    from { transform: translateY(24px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
    .modal-overlay, .modal {
        animation: none;
    }
    .shop-card {
        transition: none;
    }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-4) var(--space-2);
    flex-shrink: 0;
}

.modal-header h2 {
    font-size: 18px;
    font-weight: 700;
}

.modal-body {
    padding: 0 var(--space-4) var(--space-4);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.modal-actions {
    display: flex;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--color-border);
    flex-shrink: 0;
}

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

.detail-actions {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--color-border);
    flex-shrink: 0;
}

/* ---------- Forms ---------- */
.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text-secondary);
    margin: 0;
}

.field-label em {
    color: var(--color-danger);
    font-style: normal;
}

.field input,
.field select,
.field textarea {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    background: var(--color-surface);
    color: var(--color-text);
    min-height: 44px;
    width: 100%;
}

.field textarea {
    min-height: 80px;
    resize: vertical;
}

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

.form-error {
    background: var(--color-danger-bg);
    color: var(--color-danger);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    font-size: 14px;
    margin: 0;
}

/* ---------- Result grid (retour) ---------- */
.result-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-2);
}

.result-btn {
    min-height: 52px;
    border-radius: var(--radius-md);
    border: 2px solid transparent;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: var(--space-2);
}

.result-btn[aria-pressed="true"] {
    border-color: currentColor;
}

.result-btn.status-card_left { background: var(--status-card_left-bg); color: var(--status-card_left-fg); }
.result-btn.status-thinking { background: var(--status-thinking-bg); color: var(--status-thinking-fg); }
.result-btn.status-accepted { background: var(--status-accepted-bg); color: var(--status-accepted-fg); }
.result-btn.status-refused { background: var(--status-refused-bg); color: var(--status-refused-fg); }
.result-btn.status-closed { background: var(--status-closed-bg); color: var(--status-closed-fg); }

/* ---------- Detail sheet ---------- */
.detail-row {
    display: flex;
    gap: var(--space-3);
    align-items: flex-start;
    font-size: 15px;
}

.detail-row svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    color: var(--color-text-tertiary);
    margin-top: 1px;
}

.detail-notes {
    white-space: pre-wrap;
    font-size: 15px;
    color: var(--color-text);
    background: var(--color-bg);
    border-radius: var(--radius-sm);
    padding: var(--space-3);
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.history-item {
    display: flex;
    gap: var(--space-3);
    align-items: flex-start;
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--color-border);
    font-size: 14px;
}

.history-item:last-child {
    border-bottom: none;
}

.history-date {
    color: var(--color-text-tertiary);
    font-size: 13px;
    flex-shrink: 0;
    width: 76px;
}

.history-note {
    color: var(--color-text-secondary);
    margin-top: 2px;
}

/* ---------- Toast ---------- */
.toast {
    position: fixed;
    left: 50%;
    bottom: calc(90px + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%);
    background: #1C1C1E;
    color: #fff;
    padding: 12px 20px;
    border-radius: 999px;
    font-size: 14px;
    z-index: 100;
    box-shadow: var(--shadow-lg);
    animation: toast-in var(--duration-base) var(--ease-out);
}

.toast[hidden] {
    display: none;
}

@keyframes toast-in {
    from { opacity: 0; transform: translate(-50%, 8px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}
