/* ─── Custom properties ─────────────────────────────────────────────────── */
:root {
    --color-primary:        #3b6ef8;
    --color-primary-hover:  #2557e7;
    --color-primary-text:   #ffffff;

    --color-text:           #1e293b;
    --color-text-muted:     #64748b;
    --color-text-faint:     #94a3b8;

    --color-bg:             #f1f5f9;
    --color-surface:        #ffffff;

    --color-border:         #e2e8f0;
    --color-border-focus:   #3b6ef8;

    --color-error-bg:       #fef2f2;
    --color-error-border:   #fecaca;
    --color-error-text:     #b91c1c;

    --color-success-bg:     #f0fdf4;
    --color-success-border: #bbf7d0;
    --color-success-text:   #15803d;

    --radius:               6px;
    --radius-lg:            10px;
    --shadow-card:          0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
    --shadow-nav:           0 1px 0 var(--color-border);

    --font:                 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --font-mono:            ui-monospace, 'Cascadia Code', 'Fira Mono', monospace;
}

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

html {
    font-family:         var(--font);
    font-size:           16px;
    line-height:         1.5;
    color:               var(--color-text);
    -webkit-text-size-adjust: 100%;
}

body { margin: 0; }

h1, h2, h3, h4, h5, h6 {
    margin: 0 0 .5rem;
    line-height: 1.2;
    font-weight: 600;
}

p { margin: 0 0 1rem; }
p:last-child { margin-bottom: 0; }

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

small { font-size: .8125rem; }

/* ─── App layout ─────────────────────────────────────────────────────────── */
.app-body {
    min-height:      100vh;
    display:         flex;
    flex-direction:  column;
    background:      #ffffff;
}

/* Navigation */
.app-nav {
    position:        sticky;
    top:             0;
    z-index:         100;
    display:         flex;
    align-items:     center;
    justify-content: space-between;
    height:          56px;
    padding:         0 1.5rem;
    background:      #0f172a;
    box-shadow:      0 1px 3px rgba(0,0,0,.35);
}

.nav-brand {
    font-size:       1.125rem;
    font-weight:     700;
    color:           #ffffff;
    letter-spacing:  -.01em;
    text-decoration: none;
}
.nav-brand:hover { text-decoration: none; color: #cbd5e1; }

.nav-links {
    display:     flex;
    align-items: center;
    gap:         .25rem;
    flex:        1;
    padding:     0 1.5rem;
}

.nav-link {
    padding:         .375rem .625rem;
    font-size:       .9375rem;
    color:           #94a3b8;
    border-radius:   var(--radius);
    text-decoration: none;
}
.nav-link:hover {
    background:      rgba(255,255,255,.08);
    text-decoration: none;
    color:           #ffffff;
}

.nav-right {
    display:     flex;
    align-items: center;
    gap:         1.25rem;
}

.nav-company {
    font-weight: 600;
    font-size:   .9375rem;
    color:       #ffffff;
}

.nav-user {
    color:     #64748b;
    font-size: .875rem;
}

.nav-logout {
    font-size: .875rem;
    color:     #64748b;
}
.nav-logout:hover { color: #94a3b8; text-decoration: none; }

/* Main */
.app-main {
    flex:    1;
    padding: 2rem 1.5rem;
    width:   100%;
    max-width: 1296px;
    margin:  0 auto;
}

.app-main h1 {
    font-size:     1.5rem;
    margin-bottom: 1.5rem;
}

/* Footer */
.app-footer {
    padding:    1rem 1.5rem;
    text-align: center;
    color:      var(--color-text-faint);
    font-size:  .8125rem;
    border-top: 1px solid var(--color-border);
}

/* ─── Login / auth pages ─────────────────────────────────────────────────── */
.login-body {
    min-height:      100vh;
    display:         flex;
    align-items:     center;
    justify-content: center;
    background:      var(--color-bg);
    padding:         1.5rem;
}

.login-box {
    width:         100%;
    max-width:     400px;
    background:    var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow:    var(--shadow-card);
    padding:       2.5rem 2rem;
}

.login-logo {
    text-align:    center;
    font-size:     1.5rem;
    font-weight:   800;
    color:         var(--color-primary);
    letter-spacing: -.02em;
    margin-bottom: 1.75rem;
}

.login-box h2 {
    font-size:     1.0625rem;
    margin-bottom: 1.25rem;
    color:         var(--color-text);
}

.login-forgot {
    text-align:  center;
    margin-top:  1rem;
    font-size:   .875rem;
    color:       var(--color-text-muted);
}

.login-back {
    display:     block;
    text-align:  center;
    margin-top:  1.25rem;
    font-size:   .875rem;
    color:       var(--color-text-muted);
}

.login-confirm {
    text-align:  center;
    color:       var(--color-text-muted);
    font-size:   .9375rem;
}

/* ─── Forms ──────────────────────────────────────────────────────────────── */
.login-form,
.forgot-form,
.reset-form {
    display:        flex;
    flex-direction: column;
    gap:            1rem;
}

.field {
    display:        flex;
    flex-direction: column;
    gap:            .375rem;
}

label {
    font-size:   .875rem;
    font-weight: 500;
    color:       var(--color-text);
}

input[type="email"],
input[type="password"],
input[type="search"],
input[type="text"] {
    width:         100%;
    padding:       .5625rem .75rem;
    font-size:     1rem;
    font-family:   var(--font);
    color:         var(--color-text);
    background:    var(--color-surface);
    border:        1px solid var(--color-border);
    border-radius: var(--radius);
    outline:       none;
    transition:    border-color .15s, box-shadow .15s;
    -webkit-appearance: none;
}

input[type="email"]:focus,
input[type="password"]:focus,
input[type="search"]:focus,
input[type="text"]:focus {
    border-color: var(--color-border-focus);
    box-shadow:   0 0 0 3px rgba(59, 110, 248, .15);
}

input::placeholder { color: var(--color-text-faint); }

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn {
    display:        inline-flex;
    align-items:    center;
    justify-content: center;
    gap:            .375rem;
    padding:        .5625rem 1.125rem;
    font-size:      .9375rem;
    font-family:    var(--font);
    font-weight:    500;
    border:         1px solid transparent;
    border-radius:  var(--radius);
    cursor:         pointer;
    text-decoration: none;
    transition:     background .15s, box-shadow .15s;
    white-space:    nowrap;
}

.btn-primary {
    background: var(--color-primary);
    color:      var(--color-primary-text);
}
.btn-primary:hover {
    background:  var(--color-primary-hover);
    box-shadow:  0 2px 6px rgba(59, 110, 248, .35);
    text-decoration: none;
    color:       var(--color-primary-text);
}

.btn-block {
    width: 100%;
}

/* ─── Feedback messages ──────────────────────────────────────────────────── */
.form-error {
    padding:       .625rem .875rem;
    font-size:     .875rem;
    border-radius: var(--radius);
    background:    var(--color-error-bg);
    border:        1px solid var(--color-error-border);
    color:         var(--color-error-text);
}

.form-success {
    padding:       .625rem .875rem;
    font-size:     .875rem;
    border-radius: var(--radius);
    background:    var(--color-success-bg);
    border:        1px solid var(--color-success-border);
    color:         var(--color-success-text);
}

.field-hint,
.form-hint {
    font-size:  .8125rem;
    color:      var(--color-text-muted);
    margin-top: -.25rem;
}

/* ─── Toolbar ────────────────────────────────────────────────────────────── */
.toolbar {
    display:         flex;
    align-items:     center;
    justify-content: space-between;
    gap:             1rem;
    margin-bottom:   1.25rem;
    flex-wrap:       wrap;
}

.toolbar-search {
    display:     flex;
    align-items: center;
    gap:         .5rem;
}

.toolbar-search input[type="search"] {
    width:     260px;
    font-size: .9375rem; /* match .btn font-size so heights are equal */
}

.toolbar-right {
    display:     flex;
    align-items: center;
    gap:         1rem;
}

/* ─── Page header (title + action button side-by-side) ───────────────────── */
.page-header {
    display:         flex;
    align-items:     baseline;
    justify-content: space-between;
    margin-bottom:   1.25rem;
}

.page-header h1 { margin-bottom: 0; }

.page-header-sub {
    font-size:            1rem;
    font-weight:          400;
    color:                var(--color-muted);
    font-variant-numeric: tabular-nums;
}

/* ─── Table ──────────────────────────────────────────────────────────────── */
.table {
    width:           100%;
    border-collapse: collapse;
    font-size:       .9375rem;
}

.table th,
.table td {
    padding:    .5rem .75rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
    vertical-align: top;
}

.table th {
    font-weight:      600;
    font-size:        .8125rem;
    text-transform:   uppercase;
    letter-spacing:   .04em;
    color:            var(--color-text-muted);
    background:       var(--color-bg);
    border-bottom-width: 2px;
}

.table tbody tr:hover td { background: #f8fafc; }

/* ─── Pagination ─────────────────────────────────────────────────────────── */
.pagination {
    display:     flex;
    align-items: center;
    gap:         1rem;
    margin-top:  1.25rem;
    font-size:   .9375rem;
}

.pagination-info { color: var(--color-text-muted); }

/* ─── Contact form layout ────────────────────────────────────────────────── */
.form-section {
    display:               grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap:                   1rem;
    margin-bottom:         1.5rem;
}

.form-actions {
    display:        flex;
    align-items:    center;
    gap:            .75rem;
    margin-top:     1.5rem;
    padding-top:    1.25rem;
    border-top:     1px solid var(--color-border);
}

.form-actions-delete {
    margin-left: auto;
    color:       var(--color-error-text);
}

/* ─── Confirm dialog ─────────────────────────────────────────────────────── */
.confirm-dialog {
    border:        1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow:    var(--shadow);
    padding:       1.5rem;
    min-width:     18rem;
    background:    var(--color-surface);
    color:         var(--color-text);
}

.confirm-dialog p {
    margin:      0 0 1.25rem;
    font-size:   1rem;
}

.confirm-dialog::backdrop {
    background: rgba(0, 0, 0, .35);
}

.confirm-dialog-actions {
    display:         flex;
    justify-content: flex-end;
    gap:             .75rem;
}

.btn-danger {
    background: var(--color-error-text);
    color:      #fff;
    border:     1px solid transparent;
}

.btn-danger:hover { background: #991b1b; }

/* Fieldsets for address blocks */
.fieldset-group {
    border:        1px solid var(--color-border);
    border-radius: var(--radius);
    padding:       1rem 1.25rem 1.25rem;
    margin:        0 0 1.5rem;
    display:       grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap:           1rem;
}

.fieldset-group legend {
    padding:     0 .5rem;
    font-size:   .8125rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color:       var(--color-text-muted);
}

/* Textarea */
textarea {
    width:         100%;
    padding:       .5625rem .75rem;
    font-size:     .9375rem;
    font-family:   var(--font);
    color:         var(--color-text);
    background:    var(--color-surface);
    border:        1px solid var(--color-border);
    border-radius: var(--radius);
    outline:       none;
    resize:        vertical;
    transition:    border-color .15s, box-shadow .15s;
    -webkit-appearance: none;
}

textarea:focus {
    border-color: var(--color-border-focus);
    box-shadow:   0 0 0 3px rgba(59, 110, 248, .15);
}

/* Textarea fields span full width in the grid */
.field:has(textarea) {
    grid-column: 1 / -1;
}

/* Secondary button */
.btn-secondary {
    background:   var(--color-surface);
    color:        var(--color-text);
    border-color: var(--color-border);
}
.btn-secondary:hover {
    background: var(--color-bg);
    text-decoration: none;
    color:      var(--color-text);
}

/* ─── Contact chrome (sub-page header + tab bar) ─────────────────────────── */
.contact-chrome {
    margin-bottom: 1.5rem;
}

.contact-chrome-header {
    display:     flex;
    align-items: baseline;
    gap:         1rem;
    margin-bottom: .75rem;
}

.contact-back {
    font-size:  .875rem;
    color:      var(--color-text-muted);
    white-space: nowrap;
    flex-shrink: 0;
}
.contact-back:hover { color: var(--color-text); }

.contact-name {
    font-size:     1.375rem;
    margin-bottom: 0;
}

.contact-subnav {
    display:       flex;
    gap:           .25rem;
    border-bottom: 2px solid var(--color-border);
    padding-bottom: 0;
}

.subnav-link {
    padding:         .5rem .875rem;
    font-size:       .9375rem;
    color:           var(--color-text-muted);
    border-radius:   var(--radius) var(--radius) 0 0;
    text-decoration: none;
    margin-bottom:   -2px;
    border-bottom:   2px solid transparent;
    transition:      color .12s, border-color .12s;
}
.subnav-link:hover {
    color:           var(--color-text);
    text-decoration: none;
}
.subnav-link--active {
    color:        var(--color-primary);
    font-weight:  600;
    border-bottom-color: var(--color-primary);
}

/* ─── Month navigation ───────────────────────────────────────────────────── */
.month-nav {
    display:         flex;
    align-items:     center;
    gap:             1rem;
    margin-bottom:   1.25rem;
}

.month-nav-label {
    font-size:   1.0625rem;
    font-weight: 600;
    min-width:   9rem;
    text-align:  center;
}

.month-nav-arrow {
    display:         inline-flex;
    align-items:     center;
    justify-content: center;
    width:           2rem;
    height:          2rem;
    border:          1px solid var(--color-border);
    border-radius:   var(--radius);
    color:           var(--color-text-muted);
    text-decoration: none;
    font-size:       1rem;
    background:      var(--color-surface);
    transition:      background .12s, color .12s;
}
.month-nav-arrow:hover {
    background:      var(--color-bg);
    color:           var(--color-text);
    text-decoration: none;
}

/* ─── Time summary stats ─────────────────────────────────────────────────── */
.time-summary {
    display:       flex;
    gap:           2rem;
    margin-bottom: 1.5rem;
    padding:       1rem 1.25rem;
    background:    var(--color-surface);
    border:        1px solid var(--color-border);
    border-radius: var(--radius);
}

.time-summary-stat {
    display:        flex;
    flex-direction: column;
    gap:            .1rem;
}

.time-summary-value {
    font-size:   1.375rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
}

.time-summary-label {
    font-size: .8125rem;
    color:     var(--color-text-muted);
}

/* Times table column widths and cell styles */
.table-times .col-date     { white-space: nowrap; width: 12rem; }
.table-times .col-duration { white-space: nowrap; width: 5rem; text-align: right; font-variant-numeric: tabular-nums; }
.table-times .col-type     { white-space: nowrap; width: 8rem; color: var(--color-text-muted); font-size: .875rem; }
.table-times .col-desc     { }
.table-times .col-billable { width: 5rem; text-align: center; }
.table-times .col-menu     { width: 1px; text-align: right; white-space: nowrap; }
.table-times .billable-yes { color: var(--color-success-text); }
.table-times .billable-no  { color: var(--color-text-faint); }

.billable-toggle {
    background:  none;
    border:      none;
    cursor:      pointer;
    padding:     0;
    font-size:   inherit;
    font-family: var(--font);
    line-height: 1;
}
.billable-toggle:hover { opacity: .6; }
.table-times thead .col-duration { text-align: right; }
.table-times thead .col-billable { text-align: center; }

/* Date column link style */
.table-times .col-date a {
    color:           var(--color-text);
    text-decoration: none;
}
.table-times .col-date a:hover { text-decoration: underline; }

/* ─── Three-dot row menu ─────────────────────────────────────────────────── */
.row-menu {
    position: relative;
    display:  inline-block;
}

.row-menu-btn {
    background:     none;
    border:         none;
    cursor:         pointer;
    padding:        .1875rem .4375rem;
    color:          var(--color-text-faint);
    font-size:      1rem;
    line-height:    1;
    border-radius:  var(--radius);
    letter-spacing: .1em;
    vertical-align: middle;
}
.row-menu-btn:hover { background: var(--color-bg); color: var(--color-text-muted); }

.row-menu-dropdown {
    position:      absolute;
    right:         0;
    top:           calc(100% + 4px);
    min-width:     175px;
    background:    var(--color-surface);
    border:        1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow:    var(--shadow-card);
    z-index:       50;
}

.row-menu-item {
    display:     block;
    width:       100%;
    text-align:  left;
    padding:     .5rem .875rem;
    background:  none;
    border:      none;
    cursor:      pointer;
    font-size:   .9375rem;
    font-family: var(--font);
    color:       var(--color-text);
    white-space: nowrap;
    border-radius: var(--radius);
}
.row-menu-item:hover { background: var(--color-bg); }

/* ─── Small button variant ───────────────────────────────────────────────── */
.btn-sm {
    padding:   .3125rem .625rem;
    font-size: .8125rem;
}

/* ─── Time entry form ────────────────────────────────────────────────────── */
.time-form-section {
    display:               grid;
    grid-template-columns: repeat(4, 1fr);
    align-items:           end;
    gap:                   1rem;
    margin-bottom:         1.5rem;
}

.time-form-section .field-checkbox {
    margin: 0 0 .1875rem;
}

.time-form-duration {
    font-variant-numeric: tabular-nums;
    font-weight:          600;
    line-height:          2.25rem;
}

/* Checkbox field: label + checkbox inline */
.field-checkbox {
    display:     flex;
    align-items: center;
    margin:      .25rem 0 1.25rem;
}

.field-checkbox label {
    display:     flex;
    align-items: center;
    gap:         .5rem;
    cursor:      pointer;
    font-size:   .9375rem;
    margin-bottom: 0;
}

.field-checkbox input[type="checkbox"] {
    width:  1rem;
    height: 1rem;
    margin: 0;
    cursor: pointer;
    accent-color: var(--color-primary);
}

/* ─── Dashboard ──────────────────────────────────────────────────────────── */
.dashboard-section {
    margin-top: 2rem;
}

.dashboard-section h2 {
    font-size:     1.0625rem;
    margin-bottom: 1rem;
    color:         var(--color-text-muted);
    font-weight:   600;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.dash-grid {
    border:        1px solid var(--color-border);
    border-radius: var(--radius);
    overflow:      hidden;
}

.dash-grid-head,
.dash-row {
    display:               grid;
    grid-template-columns: 1fr 7rem 7rem 7rem;
    gap:                   1rem;
    align-items:           center;
    padding:               .5rem .75rem;
}

.dash-grid-head {
    background:    var(--color-bg);
    border-bottom: 2px solid var(--color-border);
    font-weight:   600;
    font-size:     .8125rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color:         var(--color-text-muted);
}

.dash-head--dur { text-align: right; }

.dash-row { border-bottom: 1px solid var(--color-border); }
.dash-row:last-child { border-bottom: none; }
.dash-row:hover { background: #f8fafc; }

.dash-cell--dur {
    text-align:           right;
    font-variant-numeric: tabular-nums;
    white-space:          nowrap;
}

.dash-cell-label { display: none; }

.dash-row--bill {
    border-top: 2px solid var(--color-border);
}

.dash-row--bill .dash-cell--dur    { color: var(--color-success-text); }
.dash-row--nonbill .dash-cell--dur { color: var(--color-text-faint); }

.dash-row--totals { font-weight: 600; }

/* Per-cell billable colouring (contact rows) */
.dash-dur--all-bill { color: var(--color-success-text); }
.dash-dur--no-bill  { color: var(--color-text-faint); }

.dash-dur--mixed {
    display:        flex;
    flex-direction: column;
    align-items:    flex-end;
    gap:            .1rem;
}

.dash-dur-bill {
    font-size: .75rem;
    color:     var(--color-success-text);
}

@media (max-width: 600px) {
    .dash-grid-head { display: none; }

    .dash-row {
        display: block;
        padding: .875rem .75rem;
    }

    .dash-cell {
        display:         flex;
        justify-content: space-between;
        align-items:     baseline;
        padding:         .2rem 0;
    }

    .dash-cell--name {
        font-weight:   600;
        margin-bottom: .375rem;
        display:       block;
    }

    .dash-cell-label {
        display:     inline;
        font-size:   .8125rem;
        color:       var(--color-text-muted);
        font-weight: normal;
    }
}

/* ─── Mobile nav ─────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
    .app-nav        { padding: 0 .75rem; gap: .25rem; }
    .nav-links      { padding: 0 .25rem; }
    .nav-company,
    .nav-user       { display: none; }
    .nav-timer      { margin-right: .5rem; }
    .nav-timer-contact { display: none; }
    .nav-right      { gap: .75rem; }
    .app-main       { padding: 1.25rem .75rem; }
}

/* ─── Active timer — nav indicator ──────────────────────────────────────── */
.nav-timer {
    display:         flex;
    align-items:     center;
    gap:             .375rem;
    padding:         .25rem .75rem;
    margin-right:    1.25rem;
    background:      rgba(251,191,36,.12);
    color:           #fbbf24;
    border:          1px solid rgba(251,191,36,.25);
    border-radius:   var(--radius);
    font-size:       .875rem;
    font-weight:     500;
    text-decoration: none;
    white-space:     nowrap;
}
.nav-timer:hover { background: rgba(251,191,36,.2); color: #fde68a; text-decoration: none; }

@keyframes timer-pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: .2; }
}
.nav-timer-dot {
    color:     #f59e0b;
    font-size: .6875rem;
    animation: timer-pulse 1.5s ease-in-out infinite;
}

/* ─── Active timer — times list ──────────────────────────────────────────── */
.timer-active-badge {
    display:       inline-flex;
    align-items:   center;
    gap:           .375rem;
    padding:       .25rem .625rem;
    background:    #fff8ed;
    color:         #b45309;
    border:        1px solid #fed7aa;
    border-radius: var(--radius);
    font-size:     .8125rem;
    font-weight:   500;
}

.timer-running-row td       { background: #fffbeb !important; }
.timer-running-row:hover td { background: #fef3c7 !important; }

.duration-running {
    color:       #b45309;
    font-weight: 500;
    font-size:   .8125rem;
    white-space: nowrap;
}

/* Stop button */
.btn-stop {
    background:   #fef2f2;
    color:        #b91c1c;
    border-color: #fecaca;
}
.btn-stop:hover {
    background:      #fee2e2;
    color:           #991b1b;
    border-color:    #fca5a5;
    text-decoration: none;
}

/* Disabled button (another contact's timer is running) */
.btn-disabled {
    opacity:        .45;
    cursor:         not-allowed;
    pointer-events: none;
}

/* Inline form used for Start/Stop buttons inside flex containers */
.inline-form { display: inline; margin: 0; padding: 0; }

/* ─── Misc text helpers ───────────────────────────────────────────────────── */
.text-muted { color: var(--color-text-muted); font-size: .9375rem; }

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