/* ============================================================
   Custom Properties
   ============================================================ */
:root {
    --c-bg:           #f0f2f5;
    --c-surface:      #ffffff;
    --c-primary:      #1e2d3d;
    --c-primary-dark: #162130;
    --c-accent:       #0ea5e9;
    --c-text:         #1e293b;
    --c-text-muted:   #64748b;
    --c-border:       #e2e8f0;

    /* Team colours */
    --c-sales:        #7c3aed;
    --c-window:       #0ea5e9;
    --c-gutter:       #f59e0b;

    /* Status colours */
    --c-scheduled-bg: #dbeafe;
    --c-scheduled-fg: #1d4ed8;
    --c-completed-bg: #d1fae5;
    --c-completed-fg: #065f46;
    --c-cancelled-bg: #fee2e2;
    --c-cancelled-fg: #991b1b;

    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 20px;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.12);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.18);

    --header-h:  58px;
    --ease:      0.22s ease;
}

/* ============================================================
   Reset & Base
   ============================================================ */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, sans-serif;
    background: var(--c-bg);
    color: var(--c-text);
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

button {
    cursor: pointer;
    border: none;
    background: none;
    font-family: inherit;
    font-size: inherit;
    color: inherit;
}

select {
    font-family: inherit;
    font-size: inherit;
}

/* ============================================================
   App Header
   ============================================================ */
.app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    height: var(--header-h);
    background: var(--c-primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    box-shadow: var(--shadow-md);
}

.app-header__brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.app-header__logo {
    display: block;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: var(--c-accent);
    position: relative;
    flex-shrink: 0;
}

.app-header__logo::before,
.app-header__logo::after {
    content: '';
    position: absolute;
    background: #fff;
}

/* Simple wrench-like mark using pseudo elements */
.app-header__logo::before {
    width: 14px;
    height: 3px;
    border-radius: 2px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-45deg);
}

.app-header__logo::after {
    width: 3px;
    height: 10px;
    border-radius: 2px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -30%) rotate(-45deg);
}

.app-header__title {
    font-size: 17px;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: -0.2px;
}

.team-select {
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: var(--radius-sm);
    color: #ffffff;
    padding: 6px 28px 6px 10px;
    font-size: 13px;
    font-weight: 500;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='rgba(255,255,255,0.7)' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 9px center;
}

.team-select option {
    background: var(--c-primary);
    color: #ffffff;
}

/* ============================================================
   Main Layout
   ============================================================ */
.app-main {
    padding: 16px;
    padding-bottom: calc(74px + env(safe-area-inset-bottom));
    max-width: 480px;
    margin: 0 auto;
}

/* ============================================================
   Bottom Navigation Bar
   ============================================================ */
.app-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-width: 480px;
    margin: 0 auto;
    height: 58px;
    background: var(--c-surface);
    border-top: 1px solid var(--c-border);
    display: flex;
    z-index: 99;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.06);
    padding-bottom: env(safe-area-inset-bottom);
}

.nav-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: var(--c-text-muted);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    gap: 3px;
    transition: color var(--ease);
    -webkit-tap-highlight-color: transparent;
}

.nav-tab--active {
    color: var(--c-accent);
}

.nav-tab__icon {
    width: 22px;
    height: 22px;
}

/* ============================================================
   Calendar Navigation
   ============================================================ */
.calendar-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.nav-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--c-surface);
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-sm);
    line-height: 1;
    transition: background var(--ease), transform var(--ease);
    -webkit-tap-highlight-color: transparent;
}

.nav-btn:active {
    background: var(--c-border);
    transform: scale(0.94);
}

.calendar-nav__title {
    font-size: 18px;
    font-weight: 700;
    color: var(--c-text);
    letter-spacing: -0.3px;
}

/* ============================================================
   View Toggle
   ============================================================ */
.view-toggle {
    display: flex;
    background: var(--c-surface);
    border-radius: var(--radius-md);
    padding: 4px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
}

.view-btn {
    flex: 1;
    padding: 9px 8px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    color: var(--c-text-muted);
    transition: background var(--ease), color var(--ease);
    -webkit-tap-highlight-color: transparent;
}

.view-btn--active {
    background: var(--c-primary);
    color: #ffffff;
    box-shadow: var(--shadow-sm);
}

/* ============================================================
   Month View
   ============================================================ */
.month-grid {
    background: var(--c-surface);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.month-grid__weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    background: var(--c-primary);
    padding: 10px 0 8px;
}

.weekday-label {
    text-align: center;
    font-size: 11px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.65);
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

.month-grid__days {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
    background: var(--c-border);
}

.day-cell {
    background: var(--c-surface);
    padding: 6px 2px 8px;
    min-height: 58px;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    transition: background var(--ease);
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.day-cell:active {
    background: #f1f5f9;
}

.day-cell--empty {
    background: #f8fafc;
    cursor: default;
    pointer-events: none;
}

.day-cell--past .day-number {
    color: var(--c-text-muted);
}

.day-number {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 500;
    border-radius: 50%;
    margin-bottom: 3px;
    transition: background var(--ease), color var(--ease);
}

.day-cell--today .day-number {
    background: var(--c-accent);
    color: #ffffff;
    font-weight: 700;
}

.day-dots {
    display: flex;
    gap: 2px;
    justify-content: center;
    flex-wrap: wrap;
    max-width: 28px;
}

.dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    flex-shrink: 0;
}

.dot--sales   { background: var(--c-sales); }
.dot--window  { background: var(--c-window); }
.dot--gutter  { background: var(--c-gutter); }
.dot--default { background: var(--c-text-muted); }

/* ============================================================
   Week View
   ============================================================ */
.week-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.week-day-card {
    background: var(--c-surface);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.week-day-header {
    background: var(--c-primary);
    padding: 10px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.week-day-card--today .week-day-header {
    background: var(--c-accent);
}

.week-day-name {
    font-size: 11px;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.75);
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

.week-day-date {
    font-size: 15px;
    font-weight: 700;
    color: #ffffff;
}

.week-day-body {
    padding: 8px;
}

.week-no-appts {
    padding: 14px 8px;
    text-align: center;
    font-size: 13px;
    color: var(--c-text-muted);
}

/* ============================================================
   Appointment Card
   ============================================================ */
.appt-card {
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    margin-bottom: 6px;
    background: #f8fafc;
    border-left: 3px solid var(--c-text-muted);
    cursor: pointer;
    transition: background var(--ease), transform var(--ease);
    -webkit-tap-highlight-color: transparent;
}

.appt-card:last-child {
    margin-bottom: 0;
}

.appt-card:active {
    background: #f1f5f9;
    transform: scale(0.985);
}

.appt-card--sales  { border-left-color: var(--c-sales); }
.appt-card--window { border-left-color: var(--c-window); }
.appt-card--gutter { border-left-color: var(--c-gutter); }

.appt-card__row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 3px;
}

.appt-card__time {
    font-size: 12px;
    font-weight: 700;
    color: var(--c-accent);
    letter-spacing: 0.2px;
}

.status-badge {
    font-size: 10px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.status-badge--scheduled { background: var(--c-scheduled-bg); color: var(--c-scheduled-fg); }
.status-badge--completed { background: var(--c-completed-bg); color: var(--c-completed-fg); }
.status-badge--cancelled { background: var(--c-cancelled-bg); color: var(--c-cancelled-fg); }

.appt-card__service {
    font-size: 14px;
    font-weight: 600;
    color: var(--c-text);
    margin-bottom: 1px;
}

.appt-card__customer {
    font-size: 12px;
    color: var(--c-text-muted);
    margin-bottom: 6px;
}

.appt-card__teams {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.team-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 20px;
}

.team-badge--sales  { background: #ede9fe; color: #5b21b6; }
.team-badge--window { background: #e0f2fe; color: #0369a1; }
.team-badge--gutter { background: #fef3c7; color: #92400e; }

/* ============================================================
   Bottom Sheet & Backdrop
   ============================================================ */
.sheet-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0);
    z-index: 200;
    pointer-events: none;
    transition: background var(--ease);
}

.sheet-backdrop--visible {
    background: rgba(0, 0, 0, 0.45);
    pointer-events: all;
}

.sheet-backdrop--detail {
    z-index: 300;
}

.bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-width: 480px;
    margin: 0 auto;
    background: var(--c-surface);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    z-index: 201;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.32, 0, 0.18, 1);
    box-shadow: var(--shadow-lg);
    max-height: 78vh;
    display: flex;
    flex-direction: column;
}

.bottom-sheet--detail {
    z-index: 301;
    max-height: 85vh;
}

.bottom-sheet--open {
    transform: translateY(0);
}

.bottom-sheet__handle {
    width: 36px;
    height: 4px;
    background: var(--c-border);
    border-radius: 2px;
    margin: 12px auto 0;
    flex-shrink: 0;
}

.bottom-sheet__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px 10px;
    border-bottom: 1px solid var(--c-border);
    flex-shrink: 0;
}

.bottom-sheet__header--detail {
    border-bottom: none;
    padding-bottom: 4px;
}

.bottom-sheet__title {
    font-size: 16px;
    font-weight: 700;
    color: var(--c-text);
}

.sheet-close {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--c-border);
    color: var(--c-text-muted);
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    flex-shrink: 0;
    transition: background var(--ease);
}

.sheet-close:active {
    background: #cbd5e1;
}

.sheet-back {
    font-size: 14px;
    font-weight: 600;
    color: var(--c-accent);
    padding: 4px 0;
}

.bottom-sheet__body {
    overflow-y: auto;
    padding: 12px 16px 32px;
    flex: 1;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

/* ============================================================
   No Appointments Message
   ============================================================ */
.no-appts-msg {
    padding: 32px 16px;
    text-align: center;
    color: var(--c-text-muted);
    font-size: 14px;
}

.no-appts-msg strong {
    display: block;
    font-size: 16px;
    margin-bottom: 4px;
    color: var(--c-text);
}

/* ============================================================
   Appointment Detail
   ============================================================ */
.detail-service {
    font-size: 22px;
    font-weight: 700;
    color: var(--c-text);
    margin-bottom: 2px;
}

.detail-customer {
    font-size: 15px;
    color: var(--c-text-muted);
    margin-bottom: 10px;
}

.detail-customer--link {
    color: var(--c-accent);
    text-decoration: none;
    display: block;
}

.detail-customer--link:active {
    text-decoration: underline;
}

.detail-section {
    background: #f8fafc;
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    margin-bottom: 10px;
}

.detail-row {
    display: flex;
    flex-direction: column;
    margin-bottom: 10px;
}

.detail-row:last-child {
    margin-bottom: 0;
}

.detail-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    color: var(--c-text-muted);
    margin-bottom: 2px;
}

.detail-value {
    font-size: 14px;
    font-weight: 500;
    color: var(--c-text);
}

.detail-teams-section {
    margin-top: 4px;
}

.detail-teams-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    color: var(--c-text-muted);
    margin-bottom: 7px;
}

.detail-teams-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.detail-teams-list .team-badge {
    font-size: 13px;
    padding: 4px 12px;
}
