/* ==========================================================================
   Farsystem Client Portal - Custom Styles
   ========================================================================== */

:root {
    --fs-primary: #132e48;
    --fs-primary-light: #224769;
    --fs-accent: #f31f46;
    --fs-accent-secondary: #eb1034;
    --fs-bg: #f5f7fa;
    --fs-white: #ffffff;
    --fs-text: #333333;
    --fs-text-light: #6c757d;
    --fs-border: #e2e8f0;
    --fs-sidebar-width: 260px;
    --fs-header-height: 60px;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--fs-bg);
    color: var(--fs-text);
    min-height: 100vh;
}

/* ==========================================================================
   Sidebar
   ========================================================================== */

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--fs-sidebar-width);
    height: 100vh;
    background-color: var(--fs-primary);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
}

.sidebar-logo {
    padding: 15px;
    text-align: center;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-logo img {
    max-width: 120px;
    height: auto;
}

.sidebar-nav {
    flex: 1;
    padding: 15px 0;
    overflow-y: auto;
}

.sidebar-nav .nav-item {
    margin: 2px 10px;
}

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    padding: 10px 15px;
    color: rgba(255,255,255,0.7);
    text-decoration: none;
    border-radius: 8px;
    transition: all 0.2s ease;
    font-size: 0.9rem;
    font-weight: 500;
}

.sidebar-nav .nav-link:hover {
    background-color: rgba(255,255,255,0.1);
    color: #fff;
}

.sidebar-nav .nav-link.active {
    background-color: var(--fs-accent);
    color: #fff;
}

.sidebar-nav .nav-link i {
    width: 20px;
    margin-right: 12px;
    text-align: center;
    font-size: 1.1rem;
}

/* Sidebar submenu */
.sidebar-submenu {
    padding-left: 18px;
}

.sidebar-submenu .nav-link {
    padding: 7px 15px;
    font-size: 0.84rem;
}

.sidebar-chevron {
    font-size: 0.65rem;
    transition: transform 0.2s ease;
}

.nav-link.collapsed .sidebar-chevron {
    transform: rotate(-90deg);
}

.sidebar-section-title {
    padding: 15px 25px 5px;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255,255,255,0.4);
    font-weight: 600;
}

.sidebar-footer {
    padding: 15px 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.sidebar-footer .nav-link {
    color: rgba(255,255,255,0.5);
    font-size: 0.85rem;
}

.sidebar-footer .nav-link:hover {
    color: var(--fs-accent);
}

.sidebar-badge {
    background-color: var(--fs-accent);
    color: white !important;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 10px;
    margin-left: auto;
}

.sidebar-badge.bg-danger {
    background-color: #dc3545 !important;
}

.sidebar-badge.bg-warning {
    background-color: #fd7e14 !important;
}

/* ==========================================================================
   Main Content
   ========================================================================== */

.main-content {
    margin-left: var(--fs-sidebar-width);
    min-height: 100vh;
}

.top-header {
    height: var(--fs-header-height);
    background-color: var(--fs-white);
    border-bottom: 1px solid var(--fs-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 30px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.top-header .page-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--fs-primary);
}

.top-header .user-menu {
    display: flex;
    align-items: center;
    gap: 15px;
}

.top-header .user-name {
    font-size: 0.9rem;
    color: var(--fs-text);
    font-weight: 500;
    text-decoration: none;
    padding: 6px 12px;
    border-radius: 6px;
    transition: all 0.2s;
    cursor: pointer;
}

.top-header .user-name:hover,
.top-header .user-name.show {
    background-color: var(--fs-bg);
    color: var(--fs-primary);
}

.top-header .user-name::after {
    font-size: 0.7em;
    vertical-align: 0.15em;
    margin-left: 0.4em;
}

.top-header .dropdown-menu {
    border: 1px solid var(--fs-border);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    padding: 6px 0;
    min-width: 200px;
}

.top-header .dropdown-item {
    font-size: 0.88rem;
    padding: 8px 16px;
    color: var(--fs-text);
}

.top-header .dropdown-item:hover {
    background-color: var(--fs-bg);
}

.top-header .dropdown-item.text-danger:hover {
    background-color: #fef2f2;
}

.content-wrapper {
    padding: 30px;
}

/* ==========================================================================
   Cards & Panels
   ========================================================================== */

.card {
    background-color: var(--fs-white);
    border: 1px solid var(--fs-border);
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.card-header {
    background-color: transparent;
    border-bottom: 1px solid var(--fs-border);
    padding: 15px 20px;
    font-weight: 600;
}

.card-body {
    padding: 20px;
}

.stat-card {
    background: var(--fs-white);
    border-radius: 10px;
    padding: 20px;
    border: 1px solid var(--fs-border);
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    transition: transform 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.stat-card .stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    color: white;
    margin-bottom: 12px;
}

.stat-card .stat-icon.bg-primary { background-color: var(--fs-primary); }
.stat-card .stat-icon.bg-accent { background-color: var(--fs-accent); }
.stat-card .stat-icon.bg-success { background-color: #10b981; }
.stat-card .stat-icon.bg-warning { background-color: #f59e0b; }
.stat-card .stat-icon.bg-info { background-color: var(--fs-primary-light); }

.stat-card .stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--fs-primary);
    line-height: 1;
}

.stat-card .stat-label {
    font-size: 0.85rem;
    color: var(--fs-text-light);
    margin-top: 4px;
}

/* ==========================================================================
   Tables
   ========================================================================== */

.table {
    font-size: 0.9rem;
}

.table thead th {
    background-color: var(--fs-bg);
    color: var(--fs-primary);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--fs-border);
    padding: 12px 15px;
}

.table tbody td {
    padding: 12px 15px;
    vertical-align: middle;
    border-bottom: 1px solid var(--fs-border);
}

.table tbody tr:hover {
    background-color: rgba(19, 46, 72, 0.02);
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn-primary {
    background-color: var(--fs-primary);
    border-color: var(--fs-primary);
    border-radius: 6px;
    font-weight: 500;
    padding: 8px 20px;
}

.btn-primary:hover {
    background-color: var(--fs-primary-light);
    border-color: var(--fs-primary-light);
}

.btn-accent {
    background-color: var(--fs-accent);
    border-color: var(--fs-accent);
    color: white;
    border-radius: 6px;
    font-weight: 500;
    padding: 8px 20px;
}

.btn-accent:hover {
    background-color: var(--fs-accent-secondary);
    border-color: var(--fs-accent-secondary);
    color: white;
}

.btn-outline-primary {
    color: var(--fs-primary);
    border-color: var(--fs-primary);
    border-radius: 6px;
}

.btn-outline-primary:hover {
    background-color: var(--fs-primary);
    color: white;
}

/* ==========================================================================
   Badges / Status
   ========================================================================== */

.badge-status {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-paid, .badge-closed { background-color: #d1fae5; color: #065f46; }
.badge-pending, .badge-open { background-color: #fef3c7; color: #92400e; }
.badge-overdue, .badge-in_progress, .badge-late { background-color: #fee2e2; color: #991b1b; }
.badge-waiting_admin { background-color: #fee2e2; color: #991b1b; }
.badge-waiting_client { background-color: #dbeafe; color: #1e40af; }
.badge-draft { background-color: #e2e8f0; color: #475569; }
.badge-accepted { background-color: #d1fae5; color: #065f46; }
.badge-sent, .badge-unpaid { background-color: #dbeafe; color: #1e40af; }
.badge-canceled, .badge-cancelled, .badge-void { background-color: #fce7f3; color: #9d174d; }
.badge-expired { background-color: #f3e8ff; color: #6b21a8; }
.badge-invoiced { background-color: #d1fae5; color: #065f46; }
.badge-rejected { background-color: #fee2e2; color: #991b1b; }

/* Priority badges */
.badge-priority {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-priority-low { background-color: #e2e8f0; color: #475569; }
.badge-priority-medium { background-color: #dbeafe; color: #1e40af; }
.badge-priority-high { background-color: #fef3c7; color: #92400e; }
.badge-priority-urgent { background-color: #fee2e2; color: #991b1b; }

/* ==========================================================================
   Forms
   ========================================================================== */

.form-control, .form-select {
    border: 1px solid var(--fs-border);
    border-radius: 6px;
    padding: 8px 14px;
    font-size: 0.9rem;
}

.form-control:focus, .form-select:focus {
    border-color: var(--fs-primary);
    box-shadow: 0 0 0 3px rgba(19, 46, 72, 0.1);
}

.form-label {
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--fs-primary);
    margin-bottom: 5px;
}

/* ==========================================================================
   Auth Layout
   ========================================================================== */

.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--fs-primary) 0%, var(--fs-primary-light) 100%);
    padding: 20px;
}

.auth-card {
    background: var(--fs-white);
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    width: 100%;
    max-width: 420px;
    padding: 40px;
}

.auth-card .auth-logo {
    text-align: center;
    margin-bottom: 30px;
}

.auth-card .auth-logo img {
    max-width: 200px;
}

.auth-card h2 {
    color: var(--fs-primary);
    font-size: 1.4rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 25px;
}

.auth-card .btn-primary {
    width: 100%;
    padding: 10px;
    font-size: 1rem;
}

.auth-card .auth-footer {
    text-align: center;
    margin-top: 20px;
    font-size: 0.85rem;
}

.auth-card .auth-footer a {
    color: var(--fs-accent);
    text-decoration: none;
    font-weight: 500;
}

/* ==========================================================================
   Alerts
   ========================================================================== */

.alert {
    border-radius: 8px;
    border: none;
    font-size: 0.9rem;
}

/* ==========================================================================
   Mobile Toggle
   ========================================================================== */

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--fs-primary);
    cursor: pointer;
    padding: 5px;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    z-index: 999;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.show {
        transform: translateX(0);
    }

    .sidebar-overlay.show {
        display: block;
    }

    .main-content {
        margin-left: 0;
    }

    .sidebar-toggle {
        display: block;
    }

    .content-wrapper {
        padding: 20px 15px;
    }

    /* Card headers: always allow wrapping + gap */
    .card-header.d-flex {
        flex-wrap: wrap;
        gap: 8px;
    }

    /* All flex justify-between containers: allow wrapping */
    .d-flex.justify-content-between {
        flex-wrap: wrap;
        gap: 8px;
    }

    /* Tables: smaller font, tighter padding */
    .table {
        font-size: 0.82rem;
    }
    .table thead th,
    .table tbody td {
        padding: 10px 10px;
    }

    /* Pagination containers */
    .pagination {
        flex-wrap: wrap;
        justify-content: center;
    }
}

@media (max-width: 767.98px) {
    /* Header title truncation */
    .top-header .page-title {
        font-size: 0.95rem;
        max-width: 180px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* User dropdown name: shorter on mobile */
    .top-header .user-name {
        font-size: 0.82rem;
        padding: 4px 8px;
    }

    .top-header {
        padding: 0 15px;
    }

    /* Stat cards: compact on mobile */
    .stat-card {
        padding: 14px;
    }
    .stat-card .stat-icon {
        width: 40px;
        height: 40px;
        font-size: 1.1rem;
        margin-bottom: 8px;
    }
    .stat-card .stat-value {
        font-size: 1.5rem;
    }
    .stat-card .stat-label {
        font-size: 0.8rem;
    }

    /* Cards: tighter padding */
    .card-body {
        padding: 15px;
    }
    .card-header {
        padding: 12px 15px;
        font-size: 0.9rem;
    }

    /* Tables: even smaller on phone */
    .table {
        font-size: 0.78rem;
    }
    .table thead th {
        font-size: 0.7rem;
        padding: 8px;
    }
    .table tbody td {
        padding: 8px;
    }

    /* Service/monitor card detail rows: stack columns */
    .service-card .row .col-md-2,
    .service-card .row .col-md-3,
    .service-card .row .col-md-4 {
        flex: 0 0 50%;
        max-width: 50%;
    }

    /* Input groups: prevent overflow */
    .input-group {
        flex-wrap: nowrap;
    }
    .input-group .form-control {
        min-width: 0;
    }

    /* Cron URL inputs: truncate text */
    .cron-url-input {
        text-overflow: ellipsis;
    }

    /* Empty states: less padding */
    .empty-state {
        padding: 30px 15px;
    }
    .empty-state i {
        font-size: 2rem;
    }
}

@media (max-width: 575.98px) {
    .auth-card {
        padding: 25px;
    }

    .stat-card .stat-value {
        font-size: 1.3rem;
    }

    /* Content wrapper: minimal padding */
    .content-wrapper {
        padding: 15px 10px;
    }

    /* Header: compact */
    .top-header .page-title {
        max-width: 140px;
        font-size: 0.88rem;
    }

    /* Service card detail rows: full width columns */
    .service-card .row .col-md-1,
    .service-card .row .col-md-2,
    .service-card .row .col-md-3,
    .service-card .row .col-md-4,
    .service-card .row .col-md-8 {
        flex: 0 0 100%;
        max-width: 100%;
    }

    /* Search + filter forms: stack on mobile */
    .search-form .row > [class*="col-md-"] {
        margin-bottom: 8px;
    }

    /* Badges: slightly smaller */
    .badge-status {
        font-size: 0.7rem;
        padding: 3px 8px;
    }

    /* Alert text: smaller */
    .alert {
        font-size: 0.82rem;
        padding: 10px 12px;
    }

    /* Buttons: ensure touch-friendly size */
    .btn-sm {
        padding: 6px 10px;
        font-size: 0.8rem;
    }

    /* Card body p-0 tables: ensure no horizontal overflow */
    .card-body.p-0 {
        overflow-x: auto;
    }

    /* Pagination: compact */
    .pagination-sm .page-link {
        padding: 4px 8px;
        font-size: 0.75rem;
    }
}

/* ==========================================================================
   Utilities
   ========================================================================== */

.text-primary { color: var(--fs-primary) !important; }
.text-accent { color: var(--fs-accent) !important; }
.bg-fs-primary { background-color: var(--fs-primary) !important; }
.bg-fs-accent { background-color: var(--fs-accent) !important; }

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--fs-text-light);
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 15px;
    opacity: 0.5;
}

.empty-state p {
    font-size: 1rem;
    margin-bottom: 20px;
}

/* ==========================================================================
   WhatsApp Button
   ========================================================================== */

.whatsapp-btn {
    position: fixed;
    bottom: 25px;
    right: 25px;
    width: 56px;
    height: 56px;
    background-color: #25d366;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    z-index: 1100;
    transition: transform 0.2s, box-shadow 0.2s;
    text-decoration: none;
}

.whatsapp-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0,0,0,0.3);
    color: white;
}

@media (max-width: 991.98px) {
    .whatsapp-btn {
        bottom: 20px;
        right: 20px;
        width: 50px;
        height: 50px;
    }
    .whatsapp-btn svg {
        width: 24px;
        height: 24px;
    }
}

/* ==========================================================================
   Impersonation Bar
   ========================================================================== */
.impersonation-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    background: linear-gradient(135deg, #e65100, #bf360c);
    color: #fff;
    padding: 8px 20px;
    font-size: 0.85rem;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.impersonation-bar .btn-light {
    font-size: 0.8rem;
    font-weight: 600;
    padding: 3px 12px;
}

body.impersonating {
    --fs-impersonation-height: 42px;
}

body.impersonating .sidebar {
    top: var(--fs-impersonation-height);
    height: calc(100vh - var(--fs-impersonation-height));
}

body.impersonating .main-content {
    padding-top: var(--fs-impersonation-height);
}

body.impersonating .top-header {
    top: var(--fs-impersonation-height);
}
