/* ─────────────────────────────────────────
   TOOL TRACKER — Pierre-inspired Design
   ERN brand kept: blue #0235A8 · red #F22F00
   ───────────────────────────────────────── */

:root {
    /* ERN Brand */
    --brand-primary: #0235A8;
    --brand-red:     #F22F00;

    /* Pierre Neon Accent */
    --neon-lime:     #C8FF47;
    --neon-lime-bg:  rgba(200, 255, 71, 0.10);

    /* Dark Theme (default) */
    --bg-dark:       #080808;
    --bg-surface:    #111111;
    --bg-elevated:   #181818;
    --bg-input:      #1E1E1E;
    --text-primary:  #FFFFFF;
    --text-secondary:#666666;
    --border-color:  rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.15);

    /* Function / Category Colors */
    --color-crm:          #A78BFA;
    --color-marketing:    #F472B6;
    --color-checkout:     #34D399;
    --color-tracking:     #FBBF24;
    --color-infra:        #818CF8;
    --color-design:       #22D3EE;
    --color-productivity: #94A3B8;
    --color-other:        #6B7280;

    /* Semantic */
    --success-color: #34D399;
    --danger-color:  #FF4444;

    /* Radius */
    --radius-sm:   6px;
    --radius-md:   10px;
    --radius-lg:   14px;
    --radius-pill: 999px;

    --font-family: 'Inter', system-ui, sans-serif;
}

[data-theme="light"] {
    --bg-dark:       #F2F2F2;
    --bg-surface:    #FFFFFF;
    --bg-elevated:   #F7F7F7;
    --bg-input:      #EBEBEB;
    --text-primary:  #0A0A0A;
    --text-secondary:#888888;
    --border-color:  rgba(0, 0, 0, 0.08);
    --border-strong: rgba(0, 0, 0, 0.16);
}

/* ─── RESET ─────────────────────────────── */

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

body {
    font-family: var(--font-family);
    background-color: var(--bg-dark);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.app-container {
    max-width: 1240px;
    margin: 0 auto;
    padding: 16px 24px 48px;
}

/* ─── HEADER — Pierre pill nav ───────────── */

.main-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px 10px 20px;
    background: var(--bg-surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-pill);
    margin-bottom: 40px;
    position: sticky;
    top: 16px;
    z-index: 50;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

[data-theme="dark"] .main-header {
    background: rgba(14, 14, 14, 0.88);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 20px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.logo-section {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-img {
    height: 34px;
    width: auto;
    display: block;
}

[data-theme="light"] .logo-img {
    filter: invert(1) brightness(0.15);
}

.logo-section h1 {
    display: none;
}

.logo-section h2 {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.3px;
    white-space: nowrap;
}

h1 {
    font-size: 1.4rem;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.divider {
    color: var(--text-secondary);
    margin: 0 6px;
    font-weight: 300;
}

.subtitle {
    font-weight: 400;
    color: var(--text-secondary);
}

/* ─── VIEW NAV ───────────────────────────── */

.view-nav {
    display: flex;
    background: var(--bg-elevated);
    padding: 3px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--border-color);
    gap: 1px;
}

.nav-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 6px 14px;
    font-size: 0.78rem;
    font-weight: 500;
    border-radius: var(--radius-pill);
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    font-family: var(--font-family);
}

.nav-btn.active {
    background: #FFFFFF;
    color: #0A0A0A;
    font-weight: 700;
}

[data-theme="light"] .nav-btn.active {
    background: #0A0A0A;
    color: #FFFFFF;
}

.nav-btn:hover:not(.active) {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.06);
}

/* ─── ICON BUTTONS ───────────────────────── */

.btn-icon {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-pill);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.8rem;
}

.btn-icon:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border-color: var(--border-strong);
}

.divider-vertical {
    width: 1px;
    height: 22px;
    background-color: var(--border-color);
    margin: 0 2px;
}

/* ─── DASHBOARD STAT CARDS ───────────────── */

.dashboard {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--bg-surface);
    padding: 22px 24px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    transition: border-color 0.2s;
}

.stat-card:hover {
    border-color: var(--border-strong);
}

.stat-card h3 {
    font-size: 0.68rem;
    color: var(--text-secondary);
    font-weight: 600;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.7px;
}

.value-container {
    display: flex;
    align-items: baseline;
    gap: 3px;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 2.4rem;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -2px;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.stat-card.info-card .stat-value {
    color: var(--neon-lime);
}

.currency-symbol {
    font-size: 1rem;
    color: var(--text-secondary);
    font-weight: 400;
    letter-spacing: 0;
}

.stat-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-top: 6px;
}

/* ─── TOOLBAR ────────────────────────────── */

.toolbar {
    display: flex;
    justify-content: space-between;
    margin-bottom: 14px;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}

.search-bar {
    position: relative;
    flex: 1;
    max-width: 300px;
}

.search-bar i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.search-bar input {
    width: 100%;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    padding: 8px 12px 8px 32px;
    border-radius: var(--radius-pill);
    color: var(--text-primary);
    font-size: 0.85rem;
    outline: none;
    transition: border-color 0.2s;
}

.search-bar input:focus {
    border-color: var(--border-strong);
}

.search-bar input::placeholder {
    color: var(--text-secondary);
}

.filters {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.filter-select {
    padding: 8px 30px 8px 12px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: var(--radius-pill);
    cursor: pointer;
    font-size: 0.78rem;
    font-family: var(--font-family);
    outline: none;
    transition: border-color 0.2s;
    appearance: none;
    -webkit-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 d='M1 1l4 4 4-4' stroke='%23666' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
}

.filter-select:focus {
    border-color: var(--border-strong);
}

/* ─── BUTTONS ────────────────────────────── */

.btn-primary {
    background: var(--neon-lime);
    color: #0A0A0A;
    border: none;
    padding: 8px 18px;
    font-weight: 700;
    border-radius: var(--radius-pill);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 7px;
    transition: all 0.2s;
    font-size: 0.85rem;
    font-family: var(--font-family);
    letter-spacing: -0.1px;
}

.btn-primary:hover {
    background: #D8FF5A;
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(200, 255, 71, 0.25);
}

.btn-secondary {
    background: transparent;
    border: 1px solid var(--border-strong);
    color: var(--text-secondary);
    padding: 8px 18px;
    border-radius: var(--radius-pill);
    cursor: pointer;
    font-size: 0.85rem;
    font-family: var(--font-family);
    transition: all 0.2s;
}

.btn-secondary:hover {
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.3);
    background: var(--bg-elevated);
}

/* ─── TABLE ──────────────────────────────── */

.table-container {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

thead {
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border-color);
}

th {
    padding: 11px 16px;
    font-size: 0.67rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    font-weight: 600;
    letter-spacing: 0.7px;
}

td {
    padding: 13px 16px;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.875rem;
    color: var(--text-primary);
}

tr:last-child td {
    border-bottom: none;
}

tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

/* ─── BADGES ─────────────────────────────── */

.badge {
    padding: 3px 9px;
    border-radius: var(--radius-pill);
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.2px;
    display: inline-block;
}

.badge-critical {
    background: rgba(255, 68, 68, 0.12);
    color: var(--danger-color);
    border: 1px solid rgba(255, 68, 68, 0.2);
}

.badge-ok {
    background: rgba(52, 211, 153, 0.12);
    color: var(--success-color);
    border: 1px solid rgba(52, 211, 153, 0.2);
}

/* Function Badges */
.badge-crm {
    background: rgba(167, 139, 250, 0.12);
    color: var(--color-crm);
    border: 1px solid rgba(167, 139, 250, 0.25);
}

.badge-marketing {
    background: rgba(244, 114, 182, 0.12);
    color: var(--color-marketing);
    border: 1px solid rgba(244, 114, 182, 0.25);
}

.badge-checkout {
    background: rgba(52, 211, 153, 0.12);
    color: var(--color-checkout);
    border: 1px solid rgba(52, 211, 153, 0.25);
}

.badge-tracking {
    background: rgba(251, 191, 36, 0.12);
    color: var(--color-tracking);
    border: 1px solid rgba(251, 191, 36, 0.25);
}

.badge-infra {
    background: rgba(129, 140, 248, 0.12);
    color: var(--color-infra);
    border: 1px solid rgba(129, 140, 248, 0.25);
}

.badge-design {
    background: rgba(34, 211, 238, 0.12);
    color: var(--color-design);
    border: 1px solid rgba(34, 211, 238, 0.25);
}

.badge-productivity {
    background: rgba(148, 163, 184, 0.12);
    color: var(--color-productivity);
    border: 1px solid rgba(148, 163, 184, 0.25);
}

.badge-other {
    background: rgba(107, 114, 128, 0.12);
    color: var(--color-other);
    border: 1px solid rgba(107, 114, 128, 0.25);
}

/* People Type Badges */
.badge-employee {
    background: rgba(52, 211, 153, 0.12);
    color: #34D399;
    border: 1px solid rgba(52, 211, 153, 0.25);
}

.badge-freelancer {
    background: rgba(251, 191, 36, 0.12);
    color: #FBBF24;
    border: 1px solid rgba(251, 191, 36, 0.25);
}

.badge-agency {
    background: rgba(167, 139, 250, 0.12);
    color: #A78BFA;
    border: 1px solid rgba(167, 139, 250, 0.25);
}

.badge-partner {
    background: rgba(244, 114, 182, 0.12);
    color: #F472B6;
    border: 1px solid rgba(244, 114, 182, 0.25);
}

/* ─── ACTION BUTTONS (table) ─────────────── */

.actions {
    display: flex;
    gap: 4px;
}

.btn-sm {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    border-radius: var(--radius-sm);
    transition: all 0.15s;
    font-size: 0.78rem;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-sm:hover {
    color: var(--text-primary);
    background: var(--bg-elevated);
}

.btn-delete:hover {
    color: var(--danger-color);
    background: rgba(255, 68, 68, 0.1);
}

/* ─── EMPTY STATE ────────────────────────── */

.empty-state {
    padding: 56px;
    text-align: center;
    color: var(--text-secondary);
}

.empty-state i {
    font-size: 36px;
    margin-bottom: 14px;
    opacity: 0.2;
    display: block;
}

.empty-state p {
    font-size: 0.875rem;
}

/* ─── MODAL ──────────────────────────────── */

.modal {
    display: none;
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal.visible {
    display: flex;
}

.modal-content {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 500px;
    border: 1px solid var(--border-strong);
    box-shadow: 0 28px 56px rgba(0, 0, 0, 0.6);
    display: flex;
    flex-direction: column;
    max-height: 90vh;
    padding: 0;
    overflow: hidden;
}

.modal-content form {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 24px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-surface);
    flex-shrink: 0;
    z-index: 10;
}

.modal-header h2 {
    font-size: 1rem;
    font-weight: 700;
    margin: 0;
    letter-spacing: -0.3px;
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 24px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-surface);
    flex-shrink: 0;
    z-index: 10;
}

.close-modal {
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    width: 28px;
    height: 28px;
    border-radius: var(--radius-pill);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: all 0.2s;
}

.close-modal:hover {
    color: var(--text-primary);
    border-color: var(--border-strong);
}

/* ─── FORMS ──────────────────────────────── */

.form-group {
    margin-bottom: 16px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.72rem;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

input,
select,
textarea {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 0.875rem;
    outline: none;
    transition: border-color 0.2s;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--border-strong);
}

input::placeholder,
textarea::placeholder {
    color: var(--text-secondary);
}

.helper-text {
    margin-bottom: 16px;
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* Settings input with icon */
.input-with-icon {
    position: relative;
    display: flex;
    align-items: center;
}

.input-with-icon i,
.input-with-icon .currency-icon {
    position: absolute;
    left: 12px;
    color: var(--text-secondary);
    font-size: 0.82rem;
    pointer-events: none;
    z-index: 1;
}

.input-with-icon input {
    padding-left: 30px;
}

/* ─── TOGGLE SWITCH ──────────────────────── */

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: var(--bg-input);
    border: 1px solid var(--border-strong);
    transition: .3s;
    border-radius: var(--radius-pill);
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 2px;
    bottom: 2px;
    background-color: var(--text-secondary);
    transition: .3s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--neon-lime);
    border-color: var(--neon-lime);
}

input:checked + .slider:before {
    transform: translateX(20px);
    background-color: #0A0A0A;
}

.label-text {
    font-size: 0.875rem;
    color: var(--text-primary);
}

/* ─── FOOTER ─────────────────────────────── */

.main-footer {
    border-top: 1px solid var(--border-color);
    padding: 24px 0;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.78rem;
    margin-top: 48px;
}

/* ─── SETTINGS FUNCTIONS LIST ────────────── */

.functions-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.function-item {
    background: var(--bg-input);
    padding: 5px 12px;
    border-radius: var(--radius-pill);
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.function-delete {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    font-size: 13px;
    display: flex;
    align-items: center;
    line-height: 1;
    transition: color 0.15s;
}

.function-delete:hover {
    color: var(--danger-color);
}

/* ─── HIDDEN UTILITY ─────────────────────── */

.hidden {
    display: none !important;
}

/* ─── GENERAL DASHBOARD ──────────────────── */

.general-section {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 18px;
}

.section-title {
    font-size: 0.68rem;
    font-weight: 700;
    margin-bottom: 20px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.7px;
}

/* Distribution Bar */
.dist-bar-container {
    margin-bottom: 4px;
}

.dist-bar {
    display: flex;
    height: 7px;
    border-radius: var(--radius-pill);
    overflow: hidden;
    background: var(--bg-input);
}

.dist-bar-segment {
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.dist-segment-tech     { background: var(--color-infra); }
.dist-segment-overhead { background: var(--color-checkout); }
.dist-segment-people   { background: var(--color-crm); }

.dist-legend {
    display: flex;
    gap: 20px;
    margin-top: 12px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.dist-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.dist-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

.dist-dot-tech     { background: var(--color-infra); }
.dist-dot-overhead { background: var(--color-checkout); }
.dist-dot-people   { background: var(--color-crm); }

/* Category Breakdown */
.category-breakdown {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.cat-card {
    padding: 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background: var(--bg-elevated);
    border-top: 2px solid transparent;
    transition: border-color 0.2s;
}

.cat-tech     { border-top-color: var(--color-infra); }
.cat-overhead { border-top-color: var(--color-checkout); }
.cat-people   { border-top-color: var(--color-crm); }

.cat-label {
    font-size: 0.65rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    font-weight: 600;
}

.cat-monthly {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.5px;
    margin-bottom: 2px;
    font-variant-numeric: tabular-nums;
}

.cat-annual {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.cat-detail {
    font-size: 0.7rem;
    color: var(--text-secondary);
    opacity: 0.7;
}

/* Risk & Opportunity Panel */
.risk-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.risk-col-title {
    font-size: 0.67rem;
    font-weight: 700;
    color: var(--danger-color);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 7px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.risk-col-title-wins {
    color: var(--success-color);
}

.risk-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.risk-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    font-size: 0.84rem;
    line-height: 1.4;
}

.risk-danger {
    background: rgba(255, 68, 68, 0.07);
    border: 1px solid rgba(255, 68, 68, 0.12);
    color: var(--text-primary);
}

.risk-danger i {
    color: var(--danger-color);
    margin-top: 2px;
    flex-shrink: 0;
}

.risk-win {
    background: rgba(52, 211, 153, 0.07);
    border: 1px solid rgba(52, 211, 153, 0.12);
    color: var(--text-primary);
}

.risk-win i {
    color: var(--success-color);
    margin-top: 2px;
    flex-shrink: 0;
}

.risk-empty {
    color: var(--text-secondary);
    font-size: 0.82rem;
    padding: 8px 0;
}

/* Owner Spending List */
.owners-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.owner-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    transition: border-color 0.15s;
}

.owner-item:hover {
    border-color: var(--border-strong);
}

.owner-name {
    color: var(--text-primary);
    font-weight: 500;
}

.owner-cost {
    color: var(--neon-lime);
    font-size: 0.82rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

/* ─── LOADING OVERLAY ────────────────────── */

.loading-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-dark);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 999;
    gap: 16px;
    transition: opacity 0.25s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border-color);
    border-top-color: var(--neon-lime);
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-text {
    font-size: 0.8rem;
    color: var(--text-secondary);
    letter-spacing: 0.3px;
}

/* ─── TOAST NOTIFICATIONS ────────────────── */

.toast {
    position: fixed;
    bottom: 28px;
    right: 24px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    color: var(--text-primary);
    padding: 11px 16px;
    border-radius: var(--radius-md);
    font-size: 0.83rem;
    z-index: 200;
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 320px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    animation: toastIn 0.2s ease;
}

@keyframes toastIn {
    from { transform: translateY(12px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}

.toast-success { border-left: 3px solid var(--success-color); }
.toast-success i { color: var(--success-color); }

.toast-error { border-left: 3px solid var(--danger-color); }
.toast-error i { color: var(--danger-color); }

.toast-info i { color: var(--text-secondary); }

@media (max-width: 768px) {
    .toast {
        bottom: 16px;
        right: 12px;
        left: 12px;
        max-width: 100%;
    }
}

/* =============================== RESPONSIVE & POLISH =============================== */

/* ─── GLOBAL OVERFLOW PROTECTION ────────── */

html {
    overflow-x: hidden;
}

/* ─── UI POLISH (all screen sizes) ──────── */

/* Smooth view transitions */
#view-tech, #view-overhead, #view-people, #view-general {
    animation: fadeIn 0.18s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Better table row hover */
tbody tr {
    transition: background 0.12s ease;
}

/* Button active states — touch feedback */
.btn-primary:active,
.btn-secondary:active,
.btn-icon:active,
.btn-sm:active,
.nav-btn:active {
    transform: scale(0.97);
}

/* Improved empty states */
.empty-state i {
    font-size: 3rem;
}

/* Desktop nav centering (after nav moved out of header-left) */
.view-nav {
    flex: 1;
    justify-content: center;
}

/* ─── TABLET — 1024px ────────────────────── */

@media (max-width: 1024px) {
    .app-container {
        padding: 16px 16px 40px;
    }

    .category-breakdown {
        grid-template-columns: repeat(2, 1fr);
    }

    .stat-value {
        font-size: 2rem;
    }

    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* ─── MOBILE — 768px ─────────────────────── */

@media (max-width: 768px) {

    /* ── Header: two-row layout ── */
    .main-header {
        flex-wrap: wrap;
        align-items: center;
        padding: 10px 12px 0;
        top: 6px;
        border-radius: var(--radius-lg);
        margin-bottom: 20px;
        gap: 0;
    }

    .header-left {
        flex: 1;
        min-width: 0;
    }

    .header-actions {
        flex-shrink: 0;
    }

    /*
     * KEY FIX: use flex: 0 0 100% — NOT "flex: unset; flex-basis: 100%"
     * (the shorthand would reset flex-basis back to auto, breaking wrapping)
     * Also strip the pill background/border so it looks like a tab strip.
     */
    .view-nav {
        flex: 0 0 100%;
        order: 3;
        justify-content: flex-start;
        gap: 4px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding: 8px 0 10px;
        margin-top: 6px;
        /* strip desktop pill styling */
        background: transparent;
        border: none;
        border-top: 1px solid var(--border-color);
        border-radius: 0;
    }

    .view-nav::-webkit-scrollbar {
        display: none;
    }

    .nav-btn {
        flex-shrink: 0;
        font-size: 0.78rem;
        padding: 7px 13px;
        min-height: 36px;
    }

    /* ── App container ── */
    .app-container {
        padding: 10px 12px 32px;
        max-width: 100%;
    }

    .main-footer {
        padding: 20px 12px;
        text-align: center;
    }

    /* ── Stat cards: 2-column grid ── */
    .dashboard {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .stat-card {
        padding: 14px 12px;
    }

    .stat-value {
        font-size: 1.7rem;
        letter-spacing: -1px;
    }

    /* ── Toolbar ── */
    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .search-bar {
        max-width: 100%;
    }

    .filters {
        flex-wrap: wrap;
    }

    .filters .filter-select {
        flex: 1 1 calc(50% - 5px);
        min-width: 0;
    }

    .btn-primary {
        width: 100%;
        justify-content: center;
    }

    /* ── Tables → Card layout ── */
    .table-container {
        overflow: visible;
        background: transparent;
        border: none;
        border-radius: 0;
    }

    table {
        display: block;
        width: 100%;
    }

    table thead {
        display: none;
    }

    table tbody {
        display: block;
        width: 100%;
    }

    table tbody tr {
        display: block;
        margin-bottom: 10px;
        background: var(--bg-surface);
        border: 1px solid var(--border-color);
        border-radius: var(--radius-md);
        padding: 12px;
    }

    table tbody tr:hover {
        background: var(--bg-surface);
    }

    table tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 7px 0;
        border: none;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
        font-size: 0.85rem;
        min-width: 0;
        gap: 8px;
    }

    [data-theme="light"] table tbody td {
        border-bottom-color: rgba(0, 0, 0, 0.06);
    }

    table tbody td:last-child {
        border-bottom: none;
    }

    table tbody td > * {
        min-width: 0;
        max-width: 60%;
        word-break: break-word;
    }

    /* Label from data-label */
    table tbody td::before {
        content: attr(data-label);
        font-size: 0.66rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        opacity: 0.4;
        flex-shrink: 0;
        max-width: 40%;
    }

    /* Actions cell */
    table tbody td.actions {
        justify-content: flex-end;
        gap: 8px;
        padding-top: 10px;
        border-bottom: none;
    }

    table tbody td.actions::before {
        display: none;
    }

    table tbody td.actions > * {
        max-width: none;
    }

    /* ── Modals: slide up from bottom ── */
    .modal {
        align-items: flex-end;
        padding: 0;
    }

    .modal-content {
        max-width: 100%;
        width: 100%;
        margin: 0;
        border-radius: var(--radius-md) var(--radius-md) 0 0;
        max-height: 92vh;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
    }

    /* ── Forms: single column ── */
    .form-row {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    /* ── Company Overview ── */
    .category-breakdown {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .dist-legend {
        flex-wrap: wrap;
        gap: 10px;
    }

    .risk-panel {
        grid-template-columns: 1fr;
        gap: 14px;
    }

    .general-section {
        padding: 14px;
    }

    /* ── Touch targets ── */
    .btn-icon, .nav-btn {
        min-height: 40px;
        min-width: 40px;
    }

    .btn-sm {
        min-height: 36px;
        min-width: 36px;
        width: 36px;
        height: 36px;
    }
}

/* ─── SMALL MOBILE — 480px ───────────────── */

@media (max-width: 480px) {
    .dashboard {
        grid-template-columns: 1fr;
    }

    .stat-value {
        font-size: 1.5rem;
    }

    .filters .filter-select {
        flex: 1 1 100%;
    }

    .header-actions .divider-vertical {
        display: none;
    }

    .stat-card {
        padding: 14px;
    }
}
