/* ============================================================
   Dashboard – Responsive Design System
   ============================================================ */

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

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

body {
    margin: 0;
    font-family: 'Segoe UI', Arial, sans-serif;
    font-size: 15px;
    line-height: 1.45;
    color: #1f2733;
    background: #f4f6f9;
}

img { max-width: 100%; height: auto; display: block; }
a { color: #2f80ed; }
a:hover { text-decoration: underline; }

.page-container {
    padding: 16px;
    max-width: 1200px;
    margin: 0 auto;
}

/* ============================================================
   HEADER
   ============================================================ */
.header {
    background: #fff;
    border-bottom: 1px solid #e3e7ed;
}

.header-logo-row {
    text-align: center;
    padding: 16px 12px 4px;
}

.logo-img { max-width: 130px; margin: 0 auto; }

.header-title-row {
    text-align: center;
    padding: 4px 12px 0;
}

.header-title {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 400;
    color: #1f2733;
}

.header-menu-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 16px;
    padding: 10px 16px 14px;
}

.header-menu {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
    font-size: 14px;
}

.header-menu a { color: #2f80ed; text-decoration: none; }
.header-menu a:hover { text-decoration: underline; }

.header-user {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    font-size: 14px;
    font-weight: 500;
    color: #1f2733;
}

.header-user .muted {
    color: #6b7688;
    font-weight: 400;
    font-size: 0.85rem;
}

/* ============================================================
   BRANCH SELECTOR
   ============================================================ */
.branch-selector {
    background: #f8f9fa;
    border-bottom: 1px solid #e3e7ed;
    padding: 10px 16px;
}

.branch-selector form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.branch-selector label {
    font-size: 14px;
    color: #4a5361;
    font-weight: 500;
}

.branch-selector select {
    flex: 1 1 180px;
    min-width: 0;
    padding: 8px 10px;
    border-radius: 6px;
    border: 1px solid #ccd3dc;
    background: #fff;
    font-size: 14px;
}

/* ============================================================
   ALERTS
   ============================================================ */
.alert {
    background: #fef3cd;
    border: 1px solid #f5c6cb;
    color: #856404;
    padding: 14px 16px;
    border-radius: 6px;
    margin: 16px;
    font-size: 14px;
}

/* ============================================================
   KPI CARDS
   ============================================================ */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin: 16px;
}

.kpi-card {
    background: #fff;
    padding: 14px 16px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    min-width: 0;
}

.kpi-label {
    font-size: 13px;
    color: #6b7688;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.kpi-value {
    font-size: 1.25rem;
    font-weight: 600;
    color: #1f2733;
    word-break: break-word;
}

/* ============================================================
   TABLES
   ============================================================ */
.table-wrapper,
.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    margin: 12px 16px;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 520px;
    font-size: 14px;
}

th, td {
    padding: 10px 14px;
    border-bottom: 1px solid #e3e7ed;
    text-align: left;
    white-space: nowrap;
}

th {
    background: #f4f6f9;
    font-weight: 600;
    color: #4a5361;
    font-size: 13px;
}

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

/* ---------- Tabs ---------- */
.tab-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 12px 16px 0;
    background: #fff;
    border-bottom: 1px solid #e3e7ed;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.tab-bar::-webkit-scrollbar { height: 4px; }
.tab-bar::-webkit-scrollbar-thumb { background: #ccd3dc; border-radius: 2px; }

.tab-btn {
    flex: 0 0 auto;
    padding: 10px 16px;
    border: none;
    background: transparent;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    font-weight: 500;
    font-size: 14px;
    color: #4a5361;
    white-space: nowrap;
}

.tab-btn:hover { color: #2f80ed; }

.tab-btn.active {
    color: #2f80ed;
    border-bottom-color: #2f80ed;
}

.tab-pane { display: none; padding: 16px; }
.tab-pane.active { display: block; }

/* ============================================================
   CHARTS
   ============================================================ */
.chart-container {
    position: relative;
    width: auto;
    height: 320px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    padding: 12px;
    margin: 16px;
}

.chart-container canvas {
    width: 100% !important;
    height: 100% !important;
}

/* ============================================================
   FORMS & FILTERS
   ============================================================ */
.filter-row,
.form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 16px;
    align-items: center;
    margin: 16px;
}

.filter-row label { font-size: 14px; color: #4a5361; }

input[type="date"],
input[type="text"],
input[type="email"],
input[type="password"],
input[type="tel"],
select,
textarea {
    padding: 8px 10px;
    border: 1px solid #ccd3dc;
    border-radius: 6px;
    background: #fff;
    font-size: 14px;
    font-family: inherit;
    max-width: 100%;
}

button,
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-family: inherit;
    background: #2f80ed;
    color: #fff;
    transition: background 0.15s;
}

button:hover,
.btn:hover { background: #1a6bc4; }

.btn-secondary { background: #e2e3e5; color: #333; }
.btn-secondary:hover { background: #d0d1d4; }

.btn-sm { padding: 4px 10px; border: none; border-radius: 4px; cursor: pointer; font-size: 12px; color: white; }
.btn-edit { background: #2f80ed; color: white; }
.btn-delete { background: #e74c3c; color: white; }
.btn-unassign { background: #f39c12; color: white; }
.btn-assign { background: #27ae60; color: white; }
.btn-edit:hover { background: #1a6bc4; }
.btn-delete:hover { background: #c0392b; }
.btn-unassign:hover { background: #d68910; }
.btn-assign:hover { background: #1e8449; }

.btn-primary { background: #2f80ed; color: #fff; padding: 10px 20px; }
.btn-primary:hover { background: #1a6bc4; }
.btn-link { margin-left: 12px; color: #2f80ed; text-decoration: none; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 4px; font-weight: 500; font-size: 14px; }
.form-group input,
.form-group select { width: 100%; }

/* ---------- Branch info ---------- */
.branch-info {
    margin: 12px 16px;
    font-size: 14px;
    color: #6b7688;
}

.branch-info strong { color: #333; }

.section-title {
    font-size: 1.05rem;
    font-weight: 500;
    margin: 16px 16px 0;
}

/* ============================================================
   PAGINATION
   ============================================================ */
.pagination-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    margin: 16px;
    font-size: 14px;
}

.pagination-controls button {
    padding: 6px 12px;
    background: #fff;
    color: #333;
    border: 1px solid #ccd3dc;
}

.pagination-controls button:hover:not(:disabled) { background: #f0f2f5; }
.pagination-controls button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ============================================================
   MODAL
   ============================================================ */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.5);
    padding: 16px;
    overflow-y: auto;
}

.modal-content {
    background: #fff;
    margin: 0 auto;
    padding: 20px;
    width: 100%;
    max-width: 640px;
    border-radius: 10px;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid #e3e7ed;
    padding-bottom: 10px;
    margin-bottom: 12px;
}

.modal-header h2,
.modal-header h3 { margin: 0; font-size: 1.15rem; }

.modal-close {
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
    color: #6b7688;
    background: none;
    padding: 0 4px;
}

.modal-close:hover { color: #333; background: none; }

/* ============================================================
   LOGIN
   ============================================================ */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: #f4f6f9;
}

.login-box {
    background: #fff;
    padding: 32px 28px;
    border-radius: 10px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 360px;
}

.login-box h2 { margin: 0 0 20px; text-align: center; }
.login-box label { display: block; margin: 10px 0 4px; font-size: 14px; }
.login-box input {
    width: 100%;
    padding: 10px 12px;
    font-size: 15px;
}
.login-box button {
    width: 100%;
    padding: 12px;
    margin-top: 18px;
    font-size: 15px;
}

.error   { color: #d9534f; margin-top: 10px; font-size: 14px; }
.success { color: #28a745; margin-top: 10px; font-size: 14px; }

/* ============================================================
   SUBSCRIPTIONS
   ============================================================ */
.subscription-card {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    padding: 16px 20px;
    margin-bottom: 14px;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
}

.subscription-card .sub-info { flex: 1 1 260px; min-width: 0; }

.sub-status {
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    margin-left: 6px;
}
.sub-status.active     { background: #d4edda; color: #155724; }
.sub-status.past-due   { background: #fff3cd; color: #856404; }
.sub-status.expired    { background: #f8d7da; color: #721c24; }
.sub-status.canceled   { background: #e2e3e5; color: #383d41; }
.sub-status.revoked    { background: #f8d7da; color: #721c24; }
.sub-status.perpetual  { background: #e6f7ee; color: #157347; }

.service-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 500;
    margin-left: 6px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.service-badge.desktop   { background: #e0ecff; color: #2f80ed; }
.service-badge.dashboard { background: #e0f7ff; color: #0d8ea1; }

code {
    background: #f4f6f9;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 13px;
    font-family: Consolas, Monaco, monospace;
    word-break: break-all;
}

/* ============================================================
   ADMIN HEADER
   ============================================================ */
.admin-header {
    background: #fff;
    padding: 14px 16px;
    border-bottom: 1px solid #e3e7ed;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.admin-header h1 { margin: 0; font-size: 1.25rem; }

.admin-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
    font-size: 14px;
}

.admin-nav a { color: #2f80ed; text-decoration: none; }
.admin-nav a:hover { text-decoration: underline; }

.admin-content {
    padding: 20px 16px;
    max-width: 1200px;
    margin: 0 auto;
}

.flash-message {
    padding: 12px 14px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 14px;
}
.flash-success { background: #d4edda; color: #155724; }
.flash-error   { background: #f8d7da; color: #721c24; }

/* Admin tables */
.admin-content table {
    width: 100%;
    background: #fff;
    border-collapse: collapse;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    min-width: 640px;
}

/* Admin stat cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
    margin-bottom: 30px;
}
.stat-card {
    background: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    text-align: center;
}
.stat-number { font-size: 2rem; font-weight: 600; color: #2f80ed; }
.stat-label { color: #6b7688; margin-top: 4px; font-size: 14px; }

.business-info {
    background: #fff;
    padding: 16px 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}
.business-info h2 { margin-top: 0; }
.business-info p { margin: 4px 0; }

/* ============================================================
   RESPONSIVE BREAKPOINTS
   ============================================================ */

/* --- Tablets --- */
@media (max-width: 992px) {
    .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
    .kpi-value { font-size: 1.15rem; }
    .chart-container { height: 280px; }
}

/* --- Phones --- */
@media (max-width: 640px) {
    body { font-size: 14px; }

    .header-title { font-size: 1.25rem; }
    .logo-img { max-width: 110px; }

    .header-menu-row {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        padding: 10px 12px 14px;
    }
    .header-menu {
        justify-content: center;
        gap: 6px 14px;
        font-size: 13px;
    }
    .header-user {
        justify-content: center;
        font-size: 13px;
    }

    .branch-selector { padding: 10px 12px; }
    .branch-selector form { gap: 6px; }
    .branch-selector label { flex: 0 0 100%; }

    .kpi-grid { margin: 12px; gap: 10px; }
    .kpi-card { padding: 12px 14px; }
    .kpi-value { font-size: 1.1rem; }

    .table-wrapper,
    .table-scroll { margin: 10px 12px; }
    table { font-size: 13px; min-width: 480px; }
    th, td { padding: 8px 10px; }

    .tab-bar { padding: 8px 12px 0; }
    .tab-btn { padding: 8px 12px; font-size: 13px; }
    .tab-pane { padding: 12px; }

    .chart-container { height: 220px; margin: 12px; }
    .filter-row, .form-row { margin: 12px; gap: 8px; }
    .branch-info { margin: 10px 12px; }

    .modal-content { padding: 16px; }

    .admin-header { padding: 12px; }
    .admin-header h1 { font-size: 1.1rem; }
    .admin-nav { font-size: 13px; gap: 6px 12px; }
    .admin-content { padding: 16px 12px; }
    .admin-content table { min-width: 560px; }

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

/* --- Very small phones --- */
@media (max-width: 400px) {
    .kpi-grid { grid-template-columns: 1fr 1fr; }
    .kpi-label { font-size: 12px; }
    .kpi-value { font-size: 1rem; }

    .header-menu { font-size: 12px; gap: 6px 10px; }
    .tab-btn { padding: 7px 10px; font-size: 12px; }
    .chart-container { height: 200px; }
}

/* ============================================================
   ERROR PAGES
   ============================================================ */
.error-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: #f4f6f9;
}

.error-card {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    padding: 40px 32px;
    max-width: 560px;
    width: 100%;
    text-align: center;
}

.error-logo {
    max-width: 110px;
    margin: 0 auto 16px;
}

.error-code {
    font-size: 3.5rem;
    font-weight: 700;
    line-height: 1;
    color: #2f80ed;
    margin: 0 0 8px;
    letter-spacing: -1px;
}

.error-title {
    font-size: 1.35rem;
    font-weight: 600;
    color: #1f2733;
    margin: 0 0 12px;
}

.error-message {
    font-size: 0.95rem;
    color: #6b7688;
    margin: 0 0 24px;
    line-height: 1.5;
}

.error-detail {
    background: #f4f6f9;
    border: 1px solid #e3e7ed;
    border-radius: 6px;
    padding: 10px 14px;
    font-size: 13px;
    color: #4a5361;
    text-align: left;
    word-break: break-word;
    margin-bottom: 20px;
    font-family: Consolas, Monaco, monospace;
}

.error-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

.error-actions .btn,
.error-actions button {
    padding: 10px 20px;
    font-size: 14px;
    border-radius: 6px;
    text-decoration: none;
    min-width: 130px;
    text-align: center;
}

.btn-ghost {
    background: #e2e3e5;
    color: #333;
}
.btn-ghost:hover { background: #d0d1d4; color: #333; text-decoration: none; }

@media (max-width: 480px) {
    .error-card { padding: 28px 20px; }
    .error-code { font-size: 2.75rem; }
    .error-title { font-size: 1.15rem; }
    .error-actions { flex-direction: column; }
    .error-actions .btn,
    .error-actions button { width: 100%; }
}
