/* Nail & Hammer CRM — Mobile-first CSS */

:root {
    --blue: #1a5276;
    --blue-light: #2980b9;
    --blue-pale: #ebf5fb;
    --green: #27ae60;
    --green-pale: #eafaf1;
    --orange: #f39c12;
    --orange-pale: #fef9e7;
    --red: #e74c3c;
    --red-pale: #fdedec;
    --gray-50: #f8f9fa;
    --gray-100: #f1f3f5;
    --gray-200: #e9ecef;
    --gray-300: #dee2e6;
    --gray-400: #adb5bd;
    --gray-500: #6c757d;
    --gray-600: #495057;
    --gray-700: #343a40;
    --gray-800: #212529;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.15);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--gray-50);
    color: var(--gray-800);
    line-height: 1.5;
    padding-bottom: 80px; /* Space for bottom nav */
    min-height: 100vh;
}

/* ── Flash messages ── */
.flash-container { position: fixed; top: 0; left: 0; right: 0; z-index: 1000; padding: 8px; }
.flash {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 4px;
    animation: slideDown 0.3s ease;
}
.flash-success { background: var(--green-pale); color: #1e8449; border: 1px solid #a9dfbf; }
.flash-error { background: var(--red-pale); color: #c0392b; border: 1px solid #f5b7b1; }
@keyframes slideDown { from { transform: translateY(-100%); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ── Content ── */
.content { padding: 16px; max-width: 600px; margin: 0 auto; }

/* ── Typography ── */
h1 { font-size: 22px; font-weight: 700; margin-bottom: 16px; color: var(--gray-800); }
h2 { font-size: 18px; font-weight: 600; margin-bottom: 12px; color: var(--gray-700); }
h3 { font-size: 16px; font-weight: 600; margin-bottom: 8px; }

/* ── Cards ── */
.card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 12px;
}
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}
.card-title { font-weight: 600; font-size: 15px; }
.card-subtitle { font-size: 13px; color: var(--gray-500); }

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
    border: none;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
    gap: 6px;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--blue); color: white; }
.btn-primary:hover { background: var(--blue-light); }
.btn-success { background: var(--green); color: white; }
.btn-warning { background: var(--orange); color: white; }
.btn-danger { background: var(--red); color: white; }
.btn-secondary { background: var(--gray-200); color: var(--gray-700); }
.btn-outline { background: white; color: var(--blue); border: 2px solid var(--blue); }
.btn-sm { padding: 8px 12px; font-size: 13px; }
.btn-block { display: flex; width: 100%; margin-bottom: 8px; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-600);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.form-control {
    width: 100%;
    padding: 12px;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius);
    font-size: 16px; /* Prevents zoom on iOS */
    font-family: inherit;
    background: white;
    transition: border-color 0.2s;
    -webkit-appearance: none;
}
.form-control:focus {
    border-color: var(--blue-light);
    outline: none;
}
select.form-control {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236c757d' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}
textarea.form-control { min-height: 80px; resize: vertical; }

/* ── Status badges ── */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.badge-lead { background: var(--blue-pale); color: var(--blue); }
.badge-estimated { background: #f0e6ff; color: #7d3c98; }
.badge-scheduled { background: var(--orange-pale); color: #d68910; }
.badge-in_progress, .badge-in-progress { background: #fdebd0; color: #ca6f1e; }
.badge-completed { background: var(--green-pale); color: var(--green); }
.badge-invoiced, .badge-sent { background: #d6eaf8; color: #2471a3; }
.badge-paid { background: var(--green-pale); color: #1e8449; }
.badge-cancelled, .badge-void { background: var(--gray-100); color: var(--gray-500); }
.badge-draft { background: var(--gray-100); color: var(--gray-600); }
.badge-overdue { background: var(--red-pale); color: var(--red); }
.badge-accepted { background: var(--green-pale); color: var(--green); }
.badge-declined, .badge-expired { background: var(--red-pale); color: var(--red); }

/* ── Lists ── */
.list-item {
    display: block;
    padding: 14px 16px;
    background: white;
    border-bottom: 1px solid var(--gray-100);
    text-decoration: none;
    color: inherit;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
}
.list-item:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.list-item:last-child { border-radius: 0 0 var(--radius) var(--radius); border-bottom: none; }
.list-item:only-child { border-radius: var(--radius); }
.list-item:active { background: var(--gray-50); }
.list-group {
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    margin-bottom: 16px;
}
.list-item-row { display: flex; justify-content: space-between; align-items: center; }
.list-item-title { font-weight: 600; font-size: 15px; }
.list-item-sub { font-size: 13px; color: var(--gray-500); margin-top: 2px; }

/* ── Detail view ── */
.detail-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--gray-100);
    font-size: 14px;
}
.detail-row:last-child { border-bottom: none; }
.detail-label { color: var(--gray-500); font-weight: 500; }
.detail-value { font-weight: 500; text-align: right; max-width: 60%; word-break: break-word; }

/* ── Section headers ── */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 24px;
    margin-bottom: 8px;
}

/* ── Dashboard stats ── */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
}
.stat-card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    text-align: center;
}
.stat-number { font-size: 28px; font-weight: 700; color: var(--blue); }
.stat-label { font-size: 12px; color: var(--gray-500); text-transform: uppercase; letter-spacing: 0.5px; }

/* ── Line items table ── */
.line-items-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.line-items-table th {
    text-align: left;
    padding: 8px;
    background: var(--gray-100);
    font-size: 12px;
    text-transform: uppercase;
    color: var(--gray-500);
}
.line-items-table td { padding: 8px; border-bottom: 1px solid var(--gray-100); }
.line-items-table .text-right { text-align: right; }
.totals-row td { font-weight: 600; border-top: 2px solid var(--gray-300); }

/* ── Line item builder ── */
.line-item-row {
    display: grid;
    grid-template-columns: 1fr 50px 80px 40px;
    gap: 8px;
    margin-bottom: 8px;
    align-items: start;
}
.line-item-row input { padding: 10px 8px; font-size: 14px; }
.remove-item {
    background: var(--red-pale);
    color: var(--red);
    border: none;
    border-radius: var(--radius);
    padding: 10px;
    font-size: 18px;
    cursor: pointer;
}

/* ── Bottom navigation ── */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-around;
    padding: 6px 0;
    padding-bottom: env(safe-area-inset-bottom, 6px);
    z-index: 900;
}
.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    color: var(--gray-400);
    font-size: 10px;
    font-weight: 500;
    padding: 4px 12px;
    -webkit-tap-highlight-color: transparent;
}
.nav-item svg { width: 22px; height: 22px; margin-bottom: 2px; }
.nav-item.active { color: var(--blue); }
.nav-item.nav-add svg {
    width: 28px;
    height: 28px;
    background: var(--blue);
    color: white;
    border-radius: 50%;
    padding: 4px;
}
.nav-item.nav-add { color: var(--blue); }

/* ── Modal ── */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}
.modal-content {
    background: white;
    border-radius: 16px 16px 0 0;
    padding: 24px;
    width: 100%;
    max-width: 600px;
    animation: slideUp 0.25s ease;
}
.modal-content h3 { text-align: center; margin-bottom: 16px; }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* ── Search bar ── */
.search-bar {
    position: relative;
    margin-bottom: 16px;
}
.search-bar input {
    width: 100%;
    padding: 12px 12px 12px 40px;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius);
    font-size: 16px;
    background: white;
}
.search-bar input:focus { border-color: var(--blue-light); outline: none; }
.search-bar svg {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    color: var(--gray-400);
}

/* ── Filter tabs ── */
.filter-tabs {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 8px;
    margin-bottom: 12px;
}
.filter-tab {
    padding: 8px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    text-decoration: none;
    background: var(--gray-100);
    color: var(--gray-600);
    border: none;
    cursor: pointer;
}
.filter-tab.active { background: var(--blue); color: white; }

/* ── Empty state ── */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--gray-400);
}
.empty-state svg { width: 48px; height: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 15px; margin-bottom: 16px; }

/* ── Page header ── */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
.page-header h1 { margin-bottom: 0; }
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--blue);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 8px;
}

/* ── Login page ── */
.login-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}
.login-logo {
    font-size: 28px;
    font-weight: 800;
    color: var(--blue);
    margin-bottom: 8px;
}
.login-subtitle {
    color: var(--gray-500);
    margin-bottom: 32px;
    font-size: 14px;
}
.login-form { width: 100%; max-width: 320px; }

/* ── Utility ── */
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--gray-500); }
.text-sm { font-size: 13px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.hidden { display: none; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-8 { gap: 8px; }

/* ── Links ── */
a.action-link {
    color: var(--blue);
    text-decoration: none;
    font-weight: 500;
}

/* ── More menu ── */
.more-menu { position: relative; }
.more-menu-items {
    position: absolute;
    right: 0;
    top: 100%;
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    min-width: 180px;
    z-index: 100;
    overflow: hidden;
}
.more-menu-items a, .more-menu-items button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 12px 16px;
    border: none;
    background: none;
    font-size: 14px;
    cursor: pointer;
    color: var(--gray-700);
    text-decoration: none;
}
.more-menu-items a:active, .more-menu-items button:active {
    background: var(--gray-50);
}

/* ── Quick action buttons (Call, Text, Navigate, etc.) ── */
.quick-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.quick-action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 72px;
    padding: 12px 16px;
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-decoration: none;
    color: var(--blue);
    font-size: 12px;
    font-weight: 600;
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.1s;
}
.quick-action-btn:active { transform: scale(0.95); }
.quick-action-btn svg { width: 24px; height: 24px; margin-bottom: 4px; }

/* ── Photo attachments ── */
.photo-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 12px;
}
.photo-grid img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: var(--radius);
}
.photo-upload-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1;
    background: var(--gray-100);
    border: 2px dashed var(--gray-300);
    border-radius: var(--radius);
    color: var(--gray-400);
    cursor: pointer;
}
.photo-upload-btn svg { width: 32px; height: 32px; }

/* ── Calendar view ── */
.calendar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.calendar-nav { display: flex; gap: 8px; }
.calendar-day {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 8px;
    overflow: hidden;
}
.calendar-day-header {
    background: var(--blue-pale);
    padding: 8px 12px;
    font-weight: 600;
    font-size: 14px;
    color: var(--blue);
}
.calendar-day-header.today { background: var(--blue); color: white; }
.calendar-event {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border-bottom: 1px solid var(--gray-100);
    text-decoration: none;
    color: inherit;
}
.calendar-event:last-child { border-bottom: none; }
.calendar-no-events { padding: 10px 12px; color: var(--gray-400); font-size: 13px; font-style: italic; }

/* Auto-dismiss flash */
.flash { animation: slideDown 0.3s ease, fadeOut 0.5s ease 3s forwards; }
@keyframes fadeOut { to { opacity: 0; transform: translateY(-20px); } }
