/* ============================================================
   AMC Management System — Custom Styles
   Minimal, clean, SaaS-style admin panel
   ============================================================ */

/* ---------- CSS Variables ---------- */
:root {
    --primary: #4F46E5;
    --primary-hover: #4338CA;
    --primary-light: #EEF2FF;
    --bg-body: #F8FAFC;
    --bg-card: #FFFFFF;
    --bg-sidebar: #1E293B;
    --bg-sidebar-hover: #334155;
    --text-primary: #1E293B;
    --text-secondary: #64748B;
    --text-sidebar: #CBD5E1;
    --text-sidebar-active: #FFFFFF;
    --border-color: #E2E8F0;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --radius: 0.625rem;
    --radius-lg: 0.75rem;
    --sidebar-width: 250px;
    --topbar-height: 60px;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --transition: all 0.2s ease;
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-body);
    color: var(--text-primary);
    font-size: 0.875rem;
    line-height: 1.6;
    margin: 0;
    padding: 0;
    overflow-x: hidden;
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: var(--transition);
}

a:hover {
    color: var(--primary-hover);
}

/* ---------- Sidebar ---------- */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-sidebar);
    z-index: 1040;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-header {
    padding: 1rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    min-height: var(--topbar-height);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    color: #FFFFFF;
    font-weight: 600;
    font-size: 0.95rem;
    text-decoration: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 190px;
}

.sidebar-brand i {
    font-size: 1.25rem;
    flex-shrink: 0;
}

.sidebar-brand:hover {
    color: #FFFFFF;
    opacity: 0.9;
}

.btn-close-sidebar {
    background: none;
    border: none;
    color: var(--text-sidebar);
    font-size: 1.125rem;
    cursor: pointer;
    padding: 0.25rem;
}

.sidebar-nav {
    flex: 1;
    padding: 0.75rem 0;
}

.sidebar-nav ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.nav-section-title {
    padding: 1rem 1.25rem 0.375rem;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(203, 213, 225, 0.5);
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 1.25rem;
    color: var(--text-sidebar);
    font-size: 0.8125rem;
    font-weight: 400;
    text-decoration: none;
    transition: var(--transition);
    border-left: 3px solid transparent;
}

.sidebar-nav a:hover {
    background: var(--bg-sidebar-hover);
    color: var(--text-sidebar-active);
}

.sidebar-nav a.active {
    background: rgba(79, 70, 229, 0.15);
    color: var(--text-sidebar-active);
    border-left-color: var(--primary);
    font-weight: 500;
}

.sidebar-nav a i {
    font-size: 1.05rem;
    width: 1.25rem;
    text-align: center;
    flex-shrink: 0;
}

/* ---------- Sidebar Overlay (mobile) ---------- */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 1035;
    backdrop-filter: blur(2px);
}

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

/* ---------- Main Content ---------- */
.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    transition: margin 0.3s ease;
}

/* ---------- Top Bar ---------- */
.topbar {
    height: var(--topbar-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 1020;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.topbar-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
    color: var(--text-primary);
}

.topbar-toggle {
    color: var(--text-primary);
    font-size: 1.375rem;
    padding: 0;
    text-decoration: none;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.topbar-user {
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.8125rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.topbar-user i {
    font-size: 1.375rem;
}

/* ---------- Page Content ---------- */
.page-content {
    padding: 1.5rem;
}

/* ---------- Cards ---------- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.25rem;
    font-weight: 600;
    font-size: 0.9rem;
}

.card-body {
    padding: 1.25rem;
}

/* ---------- Stat Cards ---------- */
.stat-card {
    border: none;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    cursor: default;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-card .stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.375rem;
}

.stat-card .stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.2;
    color: var(--text-primary);
}

.stat-card .stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* Dashboard overview */
.dashboard-overview {
    overflow: hidden;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    box-shadow: 0 3px 14px rgba(15, 23, 42, 0.06);
}

.overview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px;
    color: #fff;
    background: linear-gradient(120deg, #1e3a8a, #2563eb);
}

.overview-header h5 { font-weight: 700; }
.overview-header p { color: rgba(255, 255, 255, 0.75); font-size: 0.82rem; }
.overview-date {
    padding: 6px 11px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.12);
    font-size: 0.78rem;
    white-space: nowrap;
}

.overview-section { padding: 18px 20px 20px; }
.overview-financial {
    border-top: 1px solid #e5e7eb;
    background: #f8fafc;
}
.overview-section-title {
    margin-bottom: 11px;
    color: #64748b;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
.overview-grid { display: grid; gap: 12px; }
.overview-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.overview-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.overview-metric {
    display: flex;
    align-items: center;
    min-width: 0;
    min-height: 94px;
    padding: 15px;
    border: 1px solid #e5e7eb;
    border-left: 4px solid var(--metric-color);
    border-radius: 10px;
    background: #fff;
}
.metric-icon {
    display: grid;
    flex: 0 0 42px;
    width: 42px;
    height: 42px;
    margin-right: 12px;
    place-items: center;
    border-radius: 10px;
    color: var(--metric-color);
    background: var(--metric-bg);
    font-size: 1.15rem;
}
.metric-label { color: #64748b; font-size: 0.78rem; font-weight: 600; }
.metric-value {
    overflow: hidden;
    margin-top: 2px;
    color: #0f172a;
    font-size: clamp(1rem, 1.5vw, 1.35rem);
    font-weight: 750;
    line-height: 1.25;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.metric-note { margin-top: 2px; color: #94a3b8; font-size: 0.7rem; }
.metric-success { --metric-color: #059669; --metric-bg: #d1fae5; }
.metric-danger { --metric-color: #dc2626; --metric-bg: #fee2e2; }
.metric-warning { --metric-color: #d97706; --metric-bg: #fef3c7; }
.metric-primary { --metric-color: #2563eb; --metric-bg: #dbeafe; }
.metric-spent { --metric-color: #7c3aed; --metric-bg: #ede9fe; }

@media (max-width: 991.98px) {
    .overview-grid-4, .overview-grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 575.98px) {
    .overview-header { align-items: flex-start; gap: 12px; padding: 15px; }
    .overview-header p { display: none; }
    .overview-section { padding: 15px; }
    .overview-grid-4, .overview-grid-3 { grid-template-columns: 1fr; }
    .overview-metric { min-height: 78px; }
}

/* ---------- Tables ---------- */
.table {
    font-size: 0.8125rem;
    margin-bottom: 0;
}

.table th {
    font-weight: 600;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    border-bottom-width: 1px;
    padding: 0.75rem;
    white-space: nowrap;
}

.table td {
    padding: 0.625rem 0.75rem;
    vertical-align: middle;
    color: var(--text-primary);
}

.table-hover tbody tr:hover {
    background-color: var(--primary-light);
}

/* ---------- Badges ---------- */
.badge {
    font-weight: 500;
    font-size: 0.7rem;
    padding: 0.3em 0.6em;
    letter-spacing: 0.02em;
    border-radius: 0.375rem;
}

/* ---------- Buttons ---------- */
.btn {
    font-size: 0.8125rem;
    font-weight: 500;
    border-radius: 0.5rem;
    padding: 0.5rem 1rem;
    transition: var(--transition);
}

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

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

.btn-outline-primary {
    color: var(--primary);
    border-color: var(--primary);
}

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

.btn-sm {
    padding: 0.3rem 0.625rem;
    font-size: 0.75rem;
}

.btn-icon {
    width: 32px;
    height: 32px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.5rem;
}

/* ---------- Forms ---------- */
.form-control,
.form-select {
    font-size: 0.8125rem;
    border-radius: 0.5rem;
    border-color: var(--border-color);
    padding: 0.5rem 0.75rem;
    transition: var(--transition);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.form-label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.375rem;
}

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

/* ---------- Page Header ---------- */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.page-header h2 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
    color: var(--text-primary);
}

/* ---------- Search & Filter Bar ---------- */
.filter-bar {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow-sm);
}

/* ---------- Empty State ---------- */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-secondary);
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.3;
}

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

/* ---------- Login Page ---------- */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 1rem;
}

.login-card {
    background: var(--bg-card);
    border-radius: 1rem;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
    padding: 2.5rem;
    width: 100%;
    max-width: 420px;
}

.login-card h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.login-card .subtitle {
    color: var(--text-secondary);
    font-size: 0.8125rem;
    margin-bottom: 2rem;
}

.login-card .form-control {
    padding: 0.625rem 0.875rem;
    font-size: 0.875rem;
}

.login-card .btn-primary {
    padding: 0.625rem;
    font-size: 0.875rem;
    font-weight: 600;
    width: 100%;
}

/* ---------- Dropdown ---------- */
.dropdown-menu {
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    box-shadow: var(--shadow-md);
    font-size: 0.8125rem;
    padding: 0.375rem;
}

.dropdown-item {
    border-radius: 0.375rem;
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

.dropdown-item:hover {
    background-color: var(--primary-light);
}

/* ---------- Alerts ---------- */
.alert {
    font-size: 0.8125rem;
    border-radius: 0.5rem;
    padding: 0.75rem 1rem;
    border: none;
}

/* ---------- Pagination ---------- */
.pagination .page-link {
    font-size: 0.75rem;
    border-color: var(--border-color);
    color: var(--text-primary);
    padding: 0.375rem 0.625rem;
}

.pagination .page-item.active .page-link {
    background-color: var(--primary);
    border-color: var(--primary);
}

/* ---------- Notification Bell ---------- */
.topbar-notif {
    color: var(--text-secondary);
    font-size: 1.25rem;
    padding: 0.25rem;
    position: relative;
    text-decoration: none;
    transition: var(--transition);
}

.topbar-notif:hover {
    color: var(--primary);
}

.notif-badge {
    position: absolute;
    top: -2px;
    right: -6px;
    background: #EF4444;
    color: #fff;
    font-size: 0.6rem;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    animation: notifPulse 2s ease-in-out infinite;
}

@keyframes notifPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.notif-dropdown {
    width: 360px;
    max-height: 450px;
    padding: 0;
    overflow: hidden;
    border-radius: 0.75rem;
}

.notif-header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.875rem;
}

.notif-list {
    max-height: 320px;
    overflow-y: auto;
}

.notif-item {
    padding: 0.625rem 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    gap: 0.625rem;
    align-items: flex-start;
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.8125rem;
}

.notif-item:hover {
    background: var(--primary-light);
}

.notif-item.unread {
    background: #F0F9FF;
}

.notif-item .notif-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    flex-shrink: 0;
}

.notif-item .notif-text {
    flex: 1;
    min-width: 0;
}

.notif-item .notif-text .notif-title {
    font-weight: 500;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.notif-item .notif-text .notif-msg {
    color: var(--text-secondary);
    font-size: 0.75rem;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.notif-item .notif-time {
    font-size: 0.65rem;
    color: var(--text-secondary);
    white-space: nowrap;
    flex-shrink: 0;
}

.notif-footer {
    padding: 0.625rem 1rem;
    border-top: 1px solid var(--border-color);
    text-align: center;
}

/* ---------- Advanced Filter Panel ---------- */
.advanced-filters {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    margin-bottom: 1rem;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.advanced-filters .filter-toggle {
    padding: 0.75rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.8125rem;
    color: var(--text-primary);
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}

.advanced-filters .filter-toggle:hover {
    background: var(--primary-light);
}

.advanced-filters .filter-toggle i.bi-chevron-down {
    transition: transform 0.2s ease;
}

.advanced-filters.open .filter-toggle i.bi-chevron-down {
    transform: rotate(180deg);
}

.advanced-filters .filter-body {
    padding: 0 1.25rem 1rem;
    display: none;
    border-top: 1px solid var(--border-color);
    padding-top: 1rem;
}

.advanced-filters.open .filter-body {
    display: block;
}

/* ---------- Sortable Table Headers ---------- */
.table th.sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 1.25rem;
}

.table th.sortable:hover {
    background: var(--primary-light);
    color: var(--primary);
}

.table th.sortable::after {
    content: '\F282';
    font-family: 'bootstrap-icons';
    position: absolute;
    right: 0.25rem;
    font-size: 0.6rem;
    opacity: 0.3;
}

.table th.sortable.sort-asc::after {
    content: '\F235';
    opacity: 1;
    color: var(--primary);
}

.table th.sortable.sort-desc::after {
    content: '\F229';
    opacity: 1;
    color: var(--primary);
}

/* ---------- Dynamic Contact Rows ---------- */
.contact-row {
    background: #F8FAFC;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 0.75rem;
    position: relative;
}

.contact-row .contact-number {
    font-weight: 600;
    font-size: 0.75rem;
    color: var(--primary);
    margin-bottom: 0.5rem;
}

.contact-row .btn-remove-contact {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
}

/* ---------- Renewal History ---------- */
.renewal-section {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    margin-top: 1.5rem;
    overflow: hidden;
}

.renewal-section .renewal-header {
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #F8FAFC;
}

.renewal-section .renewal-header h5 {
    margin: 0;
    font-size: 0.875rem;
    font-weight: 600;
}

.renewal-summary {
    display: flex;
    gap: 1.5rem;
    padding: 0.75rem 1.25rem;
    background: #F0F9FF;
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
}

.renewal-summary .summary-item {
    text-align: center;
}

.renewal-summary .summary-item .summary-value {
    font-weight: 700;
    font-size: 1rem;
}

.renewal-summary .summary-item .summary-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    letter-spacing: 0.03em;
}

/* ---------- Export Buttons ---------- */
.export-btn {
    font-size: 0.75rem;
    padding: 0.25rem 0.625rem;
}

/* ---------- Responsive ---------- */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
    }
    
    .sidebar.show {
        transform: translateX(0);
    }
    
    .main-content {
        margin-left: 0;
    }
    
    .notif-dropdown {
        width: 300px;
    }
}

@media (max-width: 767.98px) {
    .page-content {
        padding: 1rem;
    }
    
    .stat-card .stat-value {
        font-size: 1.25rem;
    }
    
    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .topbar {
        padding: 0 1rem;
    }
    
    .invoice-header {
        flex-direction: column;
        gap: 1rem;
    }
    
    .invoice-details {
        text-align: left;
    }
    
    .invoice-meta {
        grid-template-columns: 1fr;
    }
    
    .notif-dropdown {
        width: calc(100vw - 2rem);
        right: -1rem !important;
    }
    
    .renewal-summary {
        gap: 0.75rem;
    }
}

@media (max-width: 575.98px) {
    .filter-bar .row > div {
        margin-bottom: 0.5rem;
    }

    .table-responsive {
        font-size: 0.75rem;
    }
    
    .contact-row {
        padding: 0.75rem;
    }
}
