/* === Theme === */
:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --border: #e5e7eb;
    --border-strong: #d1d5db;
    --fg: #111827;
    --fg-muted: #6b7280;
    --fg-dim: #9ca3af;
    --accent: #2563eb;
    --accent-fg: #ffffff;
    --accent-soft: #dbeafe;
    --positive: #16a34a;
    --positive-soft: #dcfce7;
    --negative: #dc2626;
    --negative-soft: #fee2e2;
    --warning: #f59e0b;
    --slot-occupied-bg: #f3f4f6;
    --slot-occupied-fg: #9ca3af;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04), 0 1px 1px rgba(0,0,0,0.03);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 -8px 32px rgba(0,0,0,0.12);
    --r-sm: 8px;
    --r-md: 12px;
    --r-lg: 16px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.4;
    background: var(--bg);
    color: var(--fg);
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

button {
    font: inherit;
    cursor: pointer;
    border: none;
    background: none;
    color: inherit;
}

input, textarea, select {
    font: inherit;
    color: inherit;
}

/* === Header === */
.app-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 12px 16px 0;
}
.title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}
.title-row h1 {
    margin: 0;
    font-size: 17px;
    font-weight: 600;
}
.badge {
    font-size: 10px;
    font-weight: 700;
    padding: 3px 7px;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.badge-dev { background: var(--warning); color: white; }
.badge-real { background: var(--positive); color: white; }

/* === Week strip === */
.week-strip {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
    padding-bottom: 10px;
}
.day-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 0 6px;
    border-radius: var(--r-sm);
    background: transparent;
    border: 1px solid transparent;
    transition: background 0.15s;
    position: relative;
}
.day-btn:active { background: var(--bg); }
.day-btn.today { color: var(--accent); }
.day-btn.selected {
    background: var(--accent);
    color: var(--accent-fg);
}
.day-btn .dow {
    font-size: 11px;
    font-weight: 500;
    opacity: 0.7;
    text-transform: lowercase;
}
.day-btn .num {
    font-size: 16px;
    font-weight: 600;
    margin-top: 2px;
}
.day-btn .count-dot {
    position: absolute;
    bottom: 2px;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--accent);
}
.day-btn.selected .count-dot { background: var(--accent-fg); }

/* === Content & list === */
.content {
    padding: 12px 16px calc(96px + var(--safe-bottom));
}
.appointments {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.empty {
    text-align: center;
    color: var(--fg-muted);
    margin: 48px 16px;
    line-height: 1.6;
}

/* === Card === */
.card {
    background: var(--surface);
    border-radius: var(--r-md);
    padding: 12px 14px;
    box-shadow: var(--shadow-sm);
    border-left: 4px solid var(--border-strong);
}
.card.status-NEW       { border-left-color: var(--accent); }
.card.status-CONFIRMED { border-left-color: var(--positive); }
.card.status-COMPLETED { border-left-color: var(--fg-muted); opacity: 0.85; }
.card.status-CANCELLED { border-left-color: var(--negative); opacity: 0.6; }

.card-row {
    display: flex;
    align-items: baseline;
    gap: 10px;
}
.card-time {
    font-size: 16px;
    font-weight: 700;
    min-width: 48px;
}
.card-status { font-size: 14px; }
.card-name {
    flex: 1;
    font-size: 15px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.card-cost {
    font-size: 14px;
    color: var(--fg-muted);
    font-variant-numeric: tabular-nums;
}
.card-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
    color: var(--fg-muted);
    font-size: 13px;
}
.card-service-tag {
    background: var(--accent-soft);
    color: var(--accent);
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
}
.card-phone {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.client-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    background: var(--bg);
    border-radius: 999px;
    font-size: 12px;
    color: var(--fg-muted);
}
.client-chip:active { background: var(--border); }

.card-comment {
    margin-top: 6px;
    font-size: 13px;
    color: var(--fg-muted);
    font-style: italic;
}

.card-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}
.action-btn {
    flex: 1;
    padding: 9px 12px;
    border-radius: var(--r-sm);
    font-size: 14px;
    font-weight: 600;
    background: var(--bg);
    color: var(--fg);
    transition: background 0.15s;
}
.action-btn:active { background: var(--border); }
.action-complete { background: var(--positive-soft); color: var(--positive); }
.action-cancel   { background: var(--negative-soft); color: var(--negative); flex: 0 0 auto; padding: 9px 14px; }

/* Inline complete form */
.inline-complete {
    margin-top: 10px;
    display: flex;
    gap: 8px;
    align-items: stretch;
}
.inline-complete input {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--r-sm);
    background: var(--surface);
    font-size: 15px;
    font-variant-numeric: tabular-nums;
}
.inline-complete input:focus {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
    border-color: var(--accent);
}
.inline-complete button {
    padding: 10px 16px;
    background: var(--positive);
    color: white;
    border-radius: var(--r-sm);
    font-weight: 600;
}
.inline-complete button:disabled { opacity: 0.5; }

/* === FAB === */
.fab {
    position: fixed;
    right: 20px;
    bottom: calc(20px + var(--safe-bottom));
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--accent-fg);
    font-size: 28px;
    font-weight: 300;
    line-height: 1;
    box-shadow: var(--shadow-md);
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s;
}
.fab:active { transform: scale(0.94); }

/* === Bottom sheet === */
.sheet {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}
.sheet[hidden] { display: none; }
.sheet-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.4);
    animation: fadeIn 0.18s ease;
}
.sheet-body {
    position: relative;
    background: var(--surface);
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
    box-shadow: var(--shadow-lg);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    padding-bottom: var(--safe-bottom);
    animation: slideUp 0.22s cubic-bezier(0.2, 0.7, 0.3, 1);
}
.sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px 8px;
    border-bottom: 1px solid var(--border);
}
.sheet-header h2 {
    margin: 0;
    font-size: 17px;
    font-weight: 600;
}
.icon-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--bg);
    color: var(--fg-muted);
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.sheet-content {
    overflow-y: auto;
    padding: 16px;
}

@keyframes fadeIn { from {opacity:0;} to {opacity:1;} }
@keyframes slideUp { from {transform: translateY(100%);} to {transform: translateY(0);} }

/* === Sheet steps === */
.sheet-steps {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px 0;
}
.step-pill {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--bg);
    color: var(--fg-muted);
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
}
.step-pill.active { background: var(--accent); color: var(--accent-fg); }
.step-pill.done { background: var(--positive); color: white; }
.step-line {
    flex: 1;
    height: 2px;
    background: var(--border);
}

/* === Form fields === */
.field {
    display: block;
    margin-bottom: 14px;
}
.field-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--fg-muted);
    margin-bottom: 6px;
}
.hint-inline {
    font-weight: 400;
    color: var(--fg-dim);
    font-size: 12px;
}
.field input,
.field textarea {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--r-sm);
    background: var(--surface);
    font-size: 15px;
}
.field input:focus,
.field textarea:focus {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
    border-color: var(--accent);
}
.field textarea { resize: vertical; min-height: 60px; }

.hint {
    font-size: 13px;
    margin: -8px 0 14px;
    padding: 8px 10px;
    border-radius: var(--r-sm);
    background: var(--accent-soft);
    color: var(--accent);
}
.hint.muted { background: var(--bg); color: var(--fg-muted); }

/* === Buttons === */
.btn-primary {
    width: 100%;
    padding: 13px;
    background: var(--accent);
    color: var(--accent-fg);
    border-radius: var(--r-sm);
    font-weight: 600;
    font-size: 15px;
    transition: opacity 0.15s;
}
.btn-primary:disabled { opacity: 0.4; }
.btn-primary:active:not(:disabled) { opacity: 0.85; }

.btn-secondary {
    padding: 13px 18px;
    background: var(--bg);
    color: var(--fg);
    border-radius: var(--r-sm);
    font-weight: 600;
    font-size: 15px;
}

.btn-row {
    display: flex;
    gap: 10px;
    margin-top: 4px;
}
.btn-row .btn-primary { flex: 1; }

/* === Date pills === */
.date-pills {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 6px;
    margin-right: -16px;
    padding-right: 16px;
}
.date-pills::-webkit-scrollbar { display: none; }
.date-pill {
    flex: 0 0 auto;
    padding: 8px 12px;
    border-radius: var(--r-sm);
    background: var(--bg);
    font-size: 13px;
    font-weight: 500;
    text-align: center;
    line-height: 1.2;
    min-width: 56px;
}
.date-pill .dow { font-size: 10px; opacity: 0.7; text-transform: lowercase; }
.date-pill.selected { background: var(--accent); color: var(--accent-fg); }

/* === Time grid === */
.time-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    max-height: 240px;
    overflow-y: auto;
    padding: 2px;
}
.slot {
    padding: 9px 0;
    border-radius: var(--r-sm);
    background: var(--bg);
    text-align: center;
    font-size: 13px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    transition: background 0.12s;
}
.slot:active { background: var(--border); }
.slot.selected { background: var(--accent); color: var(--accent-fg); }
.slot.occupied {
    background: var(--slot-occupied-bg);
    color: var(--slot-occupied-fg);
    text-decoration: line-through;
    cursor: not-allowed;
}

/* === History list === */
.client-stats {
    display: flex;
    gap: 12px;
    padding: 12px 14px;
    background: var(--bg);
    border-radius: var(--r-md);
    margin-bottom: 14px;
}
.stat {
    flex: 1;
    text-align: center;
}
.stat .num {
    font-size: 22px;
    font-weight: 700;
    color: var(--fg);
}
.stat .label {
    font-size: 11px;
    color: var(--fg-muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.history-row {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}
.history-row:last-child { border-bottom: none; }
.history-row .h-date { min-width: 100px; color: var(--fg-muted); font-size: 13px; }
.history-row .h-status { font-size: 13px; }
.history-row .h-service { flex: 1; }
.history-row .h-cost { font-variant-numeric: tabular-nums; font-weight: 600; }

/* === Toast === */
.toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--fg);
    color: var(--surface);
    padding: 10px 18px;
    border-radius: 999px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: var(--shadow-md);
    z-index: 100;
    animation: toastIn 0.2s ease;
    max-width: 90vw;
}
.toast.toast-error { background: var(--negative); }
.toast.toast-success { background: var(--positive); }
@keyframes toastIn { from {opacity:0; transform: translate(-50%, -10px);} to {opacity:1; transform: translate(-50%, 0);} }
