:root {
    --primary-color: #0C8CE9;
    --primary-dark: #0A6FC0;
    --secondary-color: #64748b;
    --accent-color: #f59e0b;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --radius: 12px;
}

html {
    overflow-y: scroll;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.5;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
}

header {
    background-color: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--primary-color);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 2rem;
    list-style: none;
}

.nav-links a {
    text-decoration: none;
    color: var(--text-main);
    font-weight: 500;
    transition: color 0.2s;
}

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

.nav-links a.button-primary {
    color: white;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 44px;
    /* Fixed height for consistency */
    padding: 0 1.5rem;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.95rem;
    text-decoration: none;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    border: 1px solid transparent;
    gap: 0.5rem;
    white-space: nowrap;
    line-height: 1;
    box-sizing: border-box;
}

/* Ensure button_to forms don't break layout */
form.button_to {
    display: inline-block;
    margin: 0;
    padding: 0;
}

form.button_to .button {
    width: 100%;
}

.button-primary {
    background-color: var(--primary-color);
    color: white;
    box-shadow: 0 4px 6px -1px rgba(12, 140, 233, 0.1), 0 2px 4px -1px rgba(12, 140, 233, 0.06);
}

.button-primary:hover {
    background-color: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 10px 15px -3px rgba(12, 140, 233, 0.15);
}

.button-outline {
    border: 1px solid #e2e8f0;
    color: var(--text-main);
    background: white;
}

.button-outline:hover {
    background-color: #f8fafc;
    border-color: #cbd5e1;
}

.button-sm {
    height: 36px;
    padding: 0 1rem;
    font-size: 0.85rem;
    border-radius: 8px;
}

.button-block,
form.button-block {
    display: flex !important;
    width: 100%;
}

form.button-block .button {
    width: 100%;
    flex: 1;
}

.button-danger {
    color: #ef4444;
    border-color: #fee2e2;
    background: #fef2f2;
}

.button-danger:hover {
    background: #fee2e2;
    border-color: #fecaca;
}

/* Hero Section */
.hero {
    padding: 4rem 0;
    text-align: center;
    background: linear-gradient(135deg, #e8f4fd 0%, #ffffff 100%);
    border-bottom: 1px solid var(--border-color);
}

.hero h1 {
    font-size: 3rem;
    font-weight: 800;
    margin-bottom: 1.5rem;
    color: var(--text-main);
}

.hero p {
    font-size: 1.25rem;
    color: var(--text-muted);
    max-width: 700px;
    margin: 0 auto 2.5rem;
}

/* Card Styles */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 1.5rem 2rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    margin-bottom: 2rem;
    overflow: hidden;
}

.card-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 1rem;
}

/* Filter form (flyer list date filter) */
.filter-card {
    margin-bottom: 1.5rem;
    padding: 1.25rem 1.5rem;
}

.filter-form {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
}

.filter-field {
    flex: 1;
}

.filter-input {
    height: 40px;
}

.filter-buttons {
    display: flex;
    gap: 0.5rem;
}

.filter-btn {
    height: 40px;
}

/* Forms */
.form-group {
    margin-bottom: 1.5rem;
}

.form-label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    font-size: 1rem;
    transition: border-color 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(12, 140, 233, 0.1);
}

/* Dashboard Layout */
.dashboard-grid {
    display: flex;
    gap: 2rem;
    padding: 2rem 0;
    align-items: flex-start;
}

.sidebar {
    width: 250px;
    flex-shrink: 0;
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 1.5rem;
    border: 1px solid var(--border-color);
    position: sticky;
    top: 2rem;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 8rem);
    /* Fixed height to avoid shrinking */
}

.main-content {
    flex: 1;
    min-width: 0;
}

/* Flyer Table List */
.flyer-table {
    width: 100%;
    border-collapse: collapse;
}

.flyer-table th {
    text-align: left;
    padding: 1rem;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    border-bottom: 2px solid var(--border-color);
}

.flyer-table td {
    padding: 1.25rem 1rem;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

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

.sidebar-menu {
    list-style: none;
}

.sidebar-item {
    margin-bottom: 0.5rem;
}

.sidebar-link {
    display: block;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    text-decoration: none;
    color: var(--text-main);
    font-weight: 500;
    transition: all 0.2s;
}

.sidebar-link:hover {
    background-color: #f1f5f9;
}

.sidebar-link.active {
    background-color: var(--primary-color);
    color: white;
}

/* Alerts */
.alert {
    padding: 1rem;
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
}

.alert-notice {
    background-color: #dcfce7;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.alert-alert {
    background-color: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

/* Loading Styles */
.loading-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.82);
    backdrop-filter: blur(5px);
    z-index: 10000;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #f1f5f9;
    border-top: 5px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1.5rem;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.button.loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}

.button.loading::after {
    content: "";
    position: absolute;
    width: 20px;
    height: 20px;
    top: 50%;
    left: 50%;
    margin: -10px 0 0 -10px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top: 3px solid white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Nav toggle button - hidden on desktop */
.nav-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem;
    color: var(--text-main);
    line-height: 1;
}

/* ===== Mobile Responsive ===== */
@media (max-width: 768px) {
    /* Prevent horizontal overflow */
    body {
        overflow-x: hidden;
    }

    .main-content {
        max-width: 100%;
        width: 100%;
        min-width: 0;
        overflow: hidden;
    }

    .dashboard-grid {
        flex-direction: column;
        gap: 0;
        padding: 1rem 0;
        width: 100%;
    }

    /* Navigation hamburger */
    .nav-toggle {
        display: block;
    }

    nav {
        position: relative;
    }

    .nav-links {
        display: none;
        position: absolute;
        top: 100%;
        left: -1rem;
        right: -1rem;
        background: var(--card-bg);
        border-bottom: 1px solid var(--border-color);
        flex-direction: column;
        padding: 0.5rem 1rem;
        gap: 0;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        z-index: 99;
    }

    .nav-links.open {
        display: flex;
    }

    .nav-links li {
        width: 100%;
    }

    .nav-links a {
        display: block;
        padding: 0.75rem 0.5rem;
    }

    .nav-links a.button-primary {
        text-align: center;
        margin: 0.5rem 0;
        border-radius: 10px;
    }

    /* Hero */
    .hero {
        padding: 2rem 0;
    }

    .hero h1 {
        font-size: 1.75rem;
    }

    .hero p {
        font-size: 1rem;
        margin-bottom: 1.5rem;
    }

    .hero-buttons {
        flex-direction: column !important;
        align-items: stretch !important;
    }

    .hero-buttons .button {
        text-align: center;
    }

    /* CTA section */
    .cta-section h2 {
        font-size: 1.75rem !important;
    }

    .cta-section p {
        font-size: 0.95rem !important;
    }

    /* Sidebar becomes horizontal tabs */
    .sidebar {
        width: 100%;
        position: static;
        height: auto;
        padding: 0.75rem;
        margin-bottom: 1rem;
    }

    .sidebar-bizmoney {
        display: none;
    }

    .sidebar-menu {
        display: flex;
        flex-direction: row;
        gap: 0.5rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .sidebar-item {
        margin-bottom: 0;
        flex-shrink: 0;
    }

    .sidebar-link {
        white-space: nowrap;
        padding: 0.5rem 0.75rem;
        font-size: 0.85rem;
    }

    /* Cards - !important overrides inline padding */
    .card {
        padding: 1rem !important;
        margin-bottom: 1rem;
    }

    .card-flush {
        padding: 0 !important;
    }

    /* Prevent form controls from overflowing */
    .form-control {
        max-width: 100%;
        box-sizing: border-box;
    }

    /* Grids - responsive overrides */
    .feature-grid {
        grid-template-columns: 1fr !important;
    }

    .stat-grid {
        grid-template-columns: 1fr !important;
    }

    .send-method-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .flyer-type-grid {
        grid-template-columns: 1fr !important;
    }

    .product-grid {
        grid-template-columns: 1fr !important;
    }

    /* Tables - card layout on mobile */
    .flyer-table thead {
        display: none;
    }

    .flyer-table tbody tr {
        display: block;
        border: 1px solid var(--border-color) !important;
        border-radius: 8px;
        margin-bottom: 0.75rem;
        padding: 0.75rem;
    }

    .flyer-table td {
        display: block;
        padding: 0.25rem 0 !important;
        border-bottom: none !important;
        text-align: left !important;
    }

    .flyer-table td[data-label]::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: 0.7rem;
        color: var(--text-muted);
        display: block;
    }

    .flyer-table td:last-child {
        margin-top: 0.5rem;
        padding-top: 0.5rem !important;
        border-top: 1px solid #f1f5f9 !important;
    }

    .flyer-table td .button-sm {
        font-size: 0.75rem;
        height: 30px;
        padding: 0 0.5rem;
    }

    /* Page headers & action buttons */
    .page-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 1rem !important;
    }

    .action-buttons {
        display: flex !important;
        flex-wrap: wrap;
        gap: 0.4rem;
    }

    /* Filter forms */
    .filter-card {
        padding: 1rem;
    }

    .filter-form {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-field {
        flex: none;
        width: 100%;
        overflow: hidden;
    }

    .filter-input {
        display: block;
        width: 100%;
        min-width: 0;
        max-width: 100%;
        -webkit-appearance: none;
        appearance: none;
    }

    .filter-buttons {
        width: 100%;
    }

    .filter-btn {
        flex: 1;
    }

    /* Upload forms - stack vertically */
    .upload-form {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.75rem !important;
    }

    .upload-form .form-control {
        width: 100% !important;
    }

    .upload-form .button {
        width: 100%;
        justify-content: center;
    }

    /* Table card buttons - consistent sizing */
    .flyer-table td form.button_to {
        display: block;
    }

    .flyer-table td form.button_to .button {
        width: 100%;
        justify-content: center;
    }

    /* Footer */
    footer {
        padding: 1rem 0 !important;
    }

    footer p {
        word-break: keep-all;
    }
}