/**
 * Pinpoint v2 — Global Stylesheet
 * Premium design system: variables, layout, components
 */

/* ── Google Fonts ──────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ── Design Tokens ──────────────────────────────────────────────────────────── */
:root {
    --brand-primary: #1b7768;
    --brand-dark: #145c53;
    --brand-light: #e0f2f1;
    --accent: #f59e0b;
    --accent-dark: #d97706;
    --danger: #ef4444;
    --danger-light: #fee2e2;
    --success: #16a34a;
    --success-light: #dcfce7;
    --warning: #f59e0b;
    --warning-light: #fffbeb;
    --muted: #64748b;
    --bg: #f1f5f9;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --sidebar-width: 220px;
    --topbar-height: 60px;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.1);
    --transition: all 0.2s ease;
}

/* ── Reset & Base ───────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 14px;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

a {
    color: var(--brand-primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

button,
input,
select,
textarea {
    font-family: inherit;
}

/* ── App Shell Layout ───────────────────────────────────────────────────────── */
.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    grid-template-rows: var(--topbar-height) 1fr;
    min-height: 100vh;
}

/* ── Top Bar ────────────────────────────────────────────────────────────────── */
#app-topbar {
    grid-column: 1 / -1;
    grid-row: 1;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-name {
    font-size: 16px;
    font-weight: 400;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

.brand-name strong {
    font-weight: 700;
    color: var(--brand-primary);
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
}

.user-greeting {
    color: var(--text-secondary);
}

.user-greeting strong {
    color: var(--text-primary);
}

.logout-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--muted);
    display: flex;
    align-items: center;
    padding: 6px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.logout-btn:hover {
    background: var(--danger-light);
    color: var(--danger);
}

.logout-btn svg {
    width: 18px;
    height: 18px;
}

/* ── Sidebar ────────────────────────────────────────────────────────────────── */
#app-sidebar {
    grid-column: 1;
    grid-row: 2;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    position: sticky;
    top: var(--topbar-height);
    height: calc(100vh - var(--topbar-height));
    overflow-y: auto;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    transition: var(--transition);
    white-space: nowrap;
}

.sidebar-link:hover {
    background: var(--brand-light);
    color: var(--brand-primary);
    text-decoration: none;
}

.sidebar-link.active {
    background: var(--brand-primary);
    color: #fff;
}

.sidebar-link svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* ── Main Content ────────────────────────────────────────────────────────────── */
#app-main {
    grid-column: 2;
    grid-row: 2;
    padding: 24px;
    max-width: 1200px;
}

/* ── Page Header ─────────────────────────────────────────────────────────────── */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}

.page-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
}

.page-subtitle {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* ── Stats Grid ──────────────────────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    display: flex;
    align-items: flex-start;
    gap: 16px;
}

.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-icon svg {
    width: 22px;
    height: 22px;
}

.stat-icon.green {
    background: var(--success-light);
    color: var(--success);
}

.stat-icon.teal {
    background: var(--brand-light);
    color: var(--brand-primary);
}

.stat-icon.amber {
    background: var(--warning-light);
    color: var(--accent);
}

.stat-icon.red {
    background: var(--danger-light);
    color: var(--danger);
}

.stat-icon.blue {
    background: #dbeafe;
    color: #1d4ed8;
}

.stat-value {
    font-size: 26px;
    font-weight: 700;
    line-height: 1;
}

.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
    font-weight: 500;
}

/* ── Cards ──────────────────────────────────────────────────────────────────── */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    overflow: hidden;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.card-title {
    font-size: 15px;
    font-weight: 600;
}

.card-body {
    padding: 20px;
}

/* ── Tables ─────────────────────────────────────────────────────────────────── */
.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

thead {
    position: sticky;
    top: 0;
    background: #f8fafc;
}

th {
    text-align: left;
    padding: 10px 14px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

td {
    padding: 12px 14px;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background: #f8fafc;
}

/* ── Forms ──────────────────────────────────────────────────────────────────── */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-control {
    width: 100%;
    height: 42px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    background: var(--surface);
    color: var(--text-primary);
    transition: var(--transition);
}

.form-control:focus {
    outline: none;
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px rgba(27, 119, 104, 0.1);
}

textarea.form-control {
    height: auto;
    padding: 10px 12px;
    resize: vertical;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-row.cols-3 {
    grid-template-columns: 1fr 1fr 1fr;
}

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 42px;
    padding: 0 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
    text-decoration: none !important;
}

.btn svg {
    width: 16px;
    height: 16px;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

.btn-primary {
    background: var(--brand-primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--brand-dark);
    transform: translateY(-1px);
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-danger:hover {
    background: #dc2626;
    transform: translateY(-1px);
}

.btn-success {
    background: var(--success);
    color: #fff;
}

.btn-success:hover {
    background: #15803d;
    transform: translateY(-1px);
}

.btn-outline {
    background: transparent;
    color: var(--brand-primary);
    border: 2px solid var(--brand-primary);
}

.btn-outline:hover {
    background: var(--brand-light);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover {
    background: var(--bg);
}

.btn-sm {
    height: 32px;
    padding: 0 12px;
    font-size: 12px;
}

.btn-full {
    width: 100%;
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 8px;
}

/* ── Badges ─────────────────────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.badge-success {
    background: var(--success-light);
    color: var(--success);
}

.badge-danger {
    background: var(--danger-light);
    color: var(--danger);
}

.badge-warning {
    background: var(--warning-light);
    color: var(--accent-dark);
}

.badge-primary {
    background: var(--brand-light);
    color: var(--brand-primary);
}

.badge-muted {
    background: #f1f5f9;
    color: var(--muted);
}

.role-admin {
    background: #ede9fe;
    color: #6d28d9;
}

.role-supervisor {
    background: #dbeafe;
    color: #1e40af;
}

.role-worker {
    background: var(--brand-light);
    color: var(--brand-primary);
}

/* ── Alerts ──────────────────────────────────────────────────────────────────── */
.alert {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    border-left: 4px solid;
    font-size: 13px;
    margin-bottom: 16px;
}

.alert-success {
    background: var(--success-light);
    border-color: var(--success);
    color: #14532d;
}

.alert-error {
    background: var(--danger-light);
    border-color: var(--danger);
    color: #7f1d1d;
}

.alert-warning {
    background: var(--warning-light);
    border-color: var(--accent);
    color: #78350f;
}

.alert-info {
    background: #dbeafe;
    border-color: #3b82f6;
    color: #1e3a8a;
}

/* ── Toast Container ─────────────────────────────────────────────────────────── */
#toast-container {
    position: fixed;
    bottom: 80px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 260px;
    max-width: 360px;
    opacity: 0;
    transform: translateY(16px);
    transition: all 0.3s ease;
    font-size: 13px;
    font-weight: 500;
    border-left: 4px solid var(--brand-primary);
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast-success {
    border-color: var(--success);
}

.toast-error {
    border-color: var(--danger);
}

.toast-icon {
    font-size: 16px;
}

.toast-success .toast-icon {
    color: var(--success);
}

.toast-error .toast-icon {
    color: var(--danger);
}

/* ── Loading Spinner ─────────────────────────────────────────────────────────── */
.spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    display: inline-block;
    margin-right: 6px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.spinner-dark {
    border-color: rgba(0, 0, 0, 0.1);
    border-top-color: var(--brand-primary);
}

/* ── Filter Bar ──────────────────────────────────────────────────────────────── */
.filter-bar {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 16px 20px;
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: flex-end;
    margin-bottom: 20px;
}

.filter-bar .form-group {
    margin-bottom: 0;
    min-width: 150px;
    flex: 1;
}

/* ── Empty State ─────────────────────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-secondary);
}

.empty-state svg {
    width: 48px;
    height: 48px;
    opacity: 0.3;
    margin-bottom: 12px;
}

.empty-state p {
    font-size: 14px;
}

/* ── Mobile Bottom Nav ───────────────────────────────────────────────────────── */
#app-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 200;
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.06);
}

.tab-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 4px;
    flex: 1;
    color: var(--muted);
    font-size: 10px;
    font-weight: 600;
    transition: var(--transition);
    text-decoration: none !important;
}

.tab-item svg {
    width: 22px;
    height: 22px;
    margin-bottom: 3px;
}

.tab-item.active {
    color: var(--brand-primary);
}

.tab-item:hover {
    color: var(--brand-primary);
    background: var(--brand-light);
}

/* ── Misc ────────────────────────────────────────────────────────────────────── */
.text-muted {
    color: var(--text-secondary);
}

.text-right {
    text-align: right;
}

.text-center {
    text-align: center;
}

.text-danger {
    color: var(--danger);
}

.text-success {
    color: var(--success);
}

.fw-bold {
    font-weight: 700;
}

.mt-4 {
    margin-top: 24px;
}

.mb-4 {
    margin-bottom: 24px;
}

.gap-1 {
    gap: 4px;
}

.gap-2 {
    gap: 8px;
}

.flex {
    display: flex;
}

.flex-1 {
    flex: 1;
}

.flex-col {
    flex-direction: column;
}

.flex-center {
    display: flex;
    align-items: center;
    justify-content: center;
}

.flex-between {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.flex-wrap {
    flex-wrap: wrap;
}

.shadow-md {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

.btn-success {
    background: var(--success);
    color: #fff;
}

.btn-success:hover {
    background: #15803d;
    transform: translateY(-1px);
}

/* ── Responsive ──────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .app-shell {
        grid-template-columns: 1fr;
        grid-template-rows: var(--topbar-height) 1fr;
    }

    #app-sidebar {
        display: none;
    }

    #app-main {
        grid-column: 1;
        padding: 16px 16px 80px;
    }

    #app-bottom-nav {
        display: flex;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .form-row.cols-3 {
        grid-template-columns: 1fr;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .filter-bar {
        flex-direction: column;
    }

    .filter-bar .form-group {
        min-width: auto;
        width: 100%;
    }

    table {
        font-size: 12px;
    }

    th,
    td {
        padding: 8px 10px;
    }
}

@media (max-width: 360px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
}