:root {
    --bg: #1a1a2e;
    --bg-light: #16213e;
    --text: #eee;
    --text-muted: #888;
    --active: #00d26a;
    --low-activity: #ffc107;
    --dormant: #ff9800;
    --inactive: #f44336;
    --never-used: #9e9e9e;
    --border: #333;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

.navbar {
    background: var(--bg-light);
    padding: 1rem 2rem;
    display: flex;
    align-items: center;
    gap: 2rem;
    border-bottom: 1px solid var(--border);
}

.nav-brand {
    font-size: 1.25rem;
    font-weight: bold;
    color: var(--active);
}

.nav-links {
    display: flex;
    list-style: none;
    gap: 1.5rem;
}

.nav-links a {
    color: var(--text-muted);
    text-decoration: none;
}

.nav-links a:hover,
.nav-links a.active {
    color: var(--text);
}

.user-info {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
}

.user-name {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.logout-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.85rem;
}

.logout-link:hover {
    color: var(--inactive);
}

.unauthorized {
    text-align: center;
    padding: 4rem 2rem;
}

.unauthorized h1 {
    color: var(--inactive);
    margin-bottom: 1rem;
}

.unauthorized p {
    margin-bottom: 1rem;
    color: var(--text-muted);
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
    overflow-x: auto;  /* contain wide tables; without this the body
                          horizontal-scrolls and the centered container
                          appears shifted right of the navbar */
}

h1 {
    margin-bottom: 0.5rem;
}

.subtitle {
    color: var(--text-muted);
    margin-bottom: 2rem;
}

.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.card {
    background: var(--bg-light);
    border-radius: 8px;
    padding: 1.5rem;
    border-left: 4px solid var(--border);
}

.card.active { border-left-color: var(--active); }
.card.low-activity { border-left-color: var(--low-activity); }
.card.dormant { border-left-color: var(--dormant); }
.card.inactive { border-left-color: var(--inactive); }
.card.never-used { border-left-color: var(--never-used); }

.card-value {
    font-size: 2.5rem;
    font-weight: bold;
}

.card.active .card-value { color: var(--active); }
.card.low-activity .card-value { color: var(--low-activity); }
.card.dormant .card-value { color: var(--dormant); }
.card.inactive .card-value { color: var(--inactive); }
.card.never-used .card-value { color: var(--never-used); }

.card-label {
    font-size: 1.1rem;
    margin-top: 0.25rem;
}

.card-desc {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.actions {
    margin-top: 2rem;
}

.btn {
    display: inline-block;
    background: var(--active);
    color: #000;
    padding: 0.75rem 1.5rem;
    border-radius: 4px;
    text-decoration: none;
    font-weight: 500;
}

.btn:hover {
    opacity: 0.9;
}

.summary-inline {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.badge {
    padding: 0.25rem 0.75rem;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 500;
}

.badge.active { background: var(--active); color: #000; }
.badge.low-activity { background: var(--low-activity); color: #000; }
.badge.dormant { background: var(--dormant); color: #000; }
.badge.inactive { background: var(--inactive); color: #fff; }
.badge.never-used { background: var(--never-used); color: #fff; }

/* DataTables overrides */
table.dataTable {
    background: var(--bg-light);
    border-collapse: collapse;
    width: 100% !important;
}

table.dataTable thead th {
    background: var(--bg);
    color: var(--text);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem;
}

table.dataTable tbody td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
}

table.dataTable tbody tr:hover {
    background: rgba(255,255,255,0.05);
}

table.dataTable tbody tr.row-active td:first-child { border-left: 3px solid var(--active); }
table.dataTable tbody tr.row-low-activity td:first-child { border-left: 3px solid var(--low-activity); }
table.dataTable tbody tr.row-dormant td:first-child { border-left: 3px solid var(--dormant); }
table.dataTable tbody tr.row-inactive td:first-child { border-left: 3px solid var(--inactive); }
table.dataTable tbody tr.row-never-used td:first-child { border-left: 3px solid var(--never-used); }

table.dataTable a {
    color: var(--text);
    text-decoration: none;
}

table.dataTable a:hover {
    color: var(--active);
}

.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter,
.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_paginate {
    color: var(--text-muted);
    padding: 0.75rem 0;
}

.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
}

.dataTables_wrapper .dataTables_paginate .paginate_button {
    color: var(--text-muted) !important;
    background: none !important;
    border: none !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current {
    color: var(--active) !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button:hover {
    color: var(--text) !important;
    background: none !important;
}

.sparkline-cell {
    padding: 0.25rem 0.5rem !important;
}

.sparkline {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 30px;
    min-width: 120px;
}

.spark-bar {
    flex: 1;
    min-width: 6px;
    background: var(--active);
    border-radius: 1px 1px 0 0;
    transition: background 0.2s;
}

.spark-bar:hover {
    background: #fff;
}

.row-low-activity .spark-bar { background: var(--low-activity); }
.row-dormant .spark-bar { background: var(--dormant); }
.row-inactive .spark-bar { background: var(--inactive); }
.row-never-used .spark-bar { background: var(--never-used); }

.filters {
    background: var(--bg-light);
    padding: 1rem 1.5rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    align-items: center;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.filter-group > label:first-child {
    color: var(--text-muted);
    font-weight: 500;
}

.checkbox {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    cursor: pointer;
    font-size: 0.9rem;
}

.checkbox input {
    cursor: pointer;
}

.date-input,
.text-input {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.4rem 0.6rem;
    border-radius: 4px;
}

.btn-small {
    background: var(--border);
    border: none;
    color: var(--text);
    padding: 0.4rem 0.75rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
}

.btn-small:hover {
    background: #444;
}

h2 {
    margin-top: 3rem;
    margin-bottom: 1rem;
}

/* Organization detail */
.org-details {
    margin: 2rem 0;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.detail-item {
    background: var(--bg-light);
    padding: 1rem;
    border-radius: 4px;
}

.detail-label {
    display: block;
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 0.25rem;
}

.detail-value {
    font-size: 1.1rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
}

.stat-card {
    background: var(--bg-light);
    padding: 1.5rem;
    border-radius: 8px;
    text-align: center;
}

.stat-value {
    font-size: 2rem;
    font-weight: bold;
    color: var(--active);
}

.stat-label {
    color: var(--text-muted);
}

.company-short {
    color: var(--text-muted);
    font-size: 0.85em;
    margin-left: 0.25rem;
}

.badge-small {
    padding: 0.15rem 0.5rem;
    border-radius: 3px;
    font-size: 0.75rem;
    font-weight: 500;
}

.badge-small.active {
    background: var(--active);
    color: #000;
}

.badge-small.inactive {
    background: var(--text-muted);
    color: #000;
}

.badge-self {
    background: #9c27b0;
    color: #fff;
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    font-size: 0.7rem;
    font-weight: 500;
    margin-left: 0.5rem;
    vertical-align: middle;
}

/* Payment status badges */
.badge-pay {
    padding: 0.2rem 0.6rem;
    border-radius: 999px;          /* full pill */
    font-size: 0.75rem;
    font-weight: 500;
    display: inline-block;
    line-height: 1.4;
}

.badge-pay-active { background: var(--active); color: #000; }
.badge-pay-trialing { background: #2196f3; color: #fff; }
.badge-pay-past_due { background: var(--dormant); color: #000; }
.badge-pay-canceled { background: #6b7280; color: #fff; }
.badge-pay-canceled_recent {
    /* Soft red pill: stands out without screaming. */
    background: rgba(244, 67, 54, 0.18);
    color: #ff8a80;
    border: 1px solid rgba(244, 67, 54, 0.45);
}
.badge-pay-no_subscription { background: var(--never-used); color: #fff; }
.badge-pay-unknown { background: var(--border); color: var(--text-muted); }
.badge-pay-error { background: #f44336; color: #fff; }

.pay-amount {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-left: 0.5rem;
}

.stripe-controls {
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

#stripe-status {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Payment column width */
#activity-table th:nth-child(2),
#activity-table td:nth-child(2) {
    min-width: 160px;
    white-space: nowrap;
}

.badge-pay {
    white-space: nowrap;
}

.back-link {
    margin-top: 2rem;
}

.back-link a {
    color: var(--text-muted);
    text-decoration: none;
}

.back-link a:hover {
    color: var(--text);
}

/* Enforcement Gap Report */
.revenue-summary {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

.money-loss {
    color: var(--inactive);
    font-weight: 500;
}

.totals-row {
    background: var(--bg) !important;
    font-size: 1.1rem;
}

.totals-row td {
    border-top: 2px solid var(--inactive) !important;
}

.gap-summary {
    margin-bottom: 2rem;
}

.badge-partner {
    background: #9c27b0;
    color: #fff;
    padding: 0.2rem 0.5rem;
    border-radius: 3px;
    font-size: 0.75rem;
    font-weight: 500;
}

.stripe-name-mismatch {
    color: #ffb74d;  /* amber: name in Stripe doesn't match org name */
    font-weight: 500;
}

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

/* Period end pills */
.period-renews        { color: var(--active);   font-weight: 500; }
.period-canceling     { color: #ffb74d;         font-weight: 500; }
.period-ended-recent  { color: var(--inactive); font-weight: 500; }
.period-ended         { color: var(--text-muted); }

/* Column-header filter row */
#activity-table thead tr.column-filters th {
    padding: 4px 6px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}
#activity-table thead tr.column-filters .col-filter {
    width: 100%;
    padding: 4px 6px;
    background: var(--bg-light);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 3px;
    font-size: 0.85rem;
    box-sizing: border-box;
}

/* Role badges */
.badge-role {
    padding: 0.2rem 0.5rem;
    border-radius: 3px;
    font-size: 0.75rem;
    font-weight: 500;
}

.badge-role-admin { background: #e91e63; color: #fff; }
.badge-role-owner { background: #9c27b0; color: #fff; }
.badge-role-user { background: var(--border); color: var(--text); }
.badge-role-technician { background: #2196f3; color: #fff; }

/* Email links */
table.dataTable a[href^="mailto:"] {
    color: #2196f3;
}

table.dataTable a[href^="mailto:"]:hover {
    color: #64b5f6;
    text-decoration: underline;
}

.findings {
    margin-top: 3rem;
    background: var(--bg-light);
    padding: 2rem;
    border-radius: 8px;
    border-left: 4px solid var(--inactive);
}

.findings h2 {
    margin-top: 0;
    color: var(--inactive);
}

.findings h3 {
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
    color: var(--text);
    font-size: 1rem;
}

.findings ul {
    margin-left: 1.5rem;
    color: var(--text-muted);
}

.findings li {
    margin-bottom: 0.5rem;
}

.findings strong {
    color: var(--text);
}
