/* -----------------------------------------------------------------------------
   1. VARIABLES & RESET
----------------------------------------------------------------------------- */
:root {
    /* Colors */
    --primary-color: #3b82f6;
    /* Blue */
    --secondary-color: #6b7280;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --info-color: #3b82f6;

    --bg-body: #f3f4f6;
    --bg-card: #ffffff;
    --bg-sidebar: #ffffff;

    --text-primary: #111827;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;

    --border-color: #e5e7eb;

    /* Layout */
    --sidebar-width: 260px;
    --header-height: 70px;

    /* Effects */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);

    --radius-md: 0.5rem;
    --radius-lg: 1rem;

    --transition-speed: 0.3s;
}

[data-theme="dark"] {
    --bg-body: #0f172a;
    --bg-card: #1e293b;
    --bg-sidebar: #1e293b;

    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;

    --border-color: #334155;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-body);
    color: var(--text-primary);
    transition: background-color var(--transition-speed), color var(--transition-speed);
}

a {
    text-decoration: none;
    color: inherit;
}

ul {
    list-style: none;
}

button {
    font-family: inherit;
}

/* -----------------------------------------------------------------------------
   2. UTILITIES
----------------------------------------------------------------------------- */
.text-primary {
    color: var(--primary-color) !important;
}

.text-success {
    color: var(--success-color) !important;
}

.text-danger {
    color: var(--danger-color) !important;
}

.text-orange {
    color: var(--warning-color) !important;
}

.text-green {
    color: var(--success-color) !important;
}

.text-red {
    color: var(--danger-color) !important;
}

.bg-light-orange {
    background-color: rgba(245, 158, 11, 0.1);
}

.bg-light-green {
    background-color: rgba(16, 185, 129, 0.1);
}

.bg-light-red {
    background-color: rgba(239, 68, 68, 0.1);
}

.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.flex-row {
    display: flex;
    align-items: center;
}

.badge {
    padding: 0.25rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-success {
    color: var(--success-color);
    background-color: rgba(16, 185, 129, 0.1);
}

.badge-danger {
    color: var(--danger-color);
    background-color: rgba(239, 68, 68, 0.1);
}

/* -----------------------------------------------------------------------------
   3. SIDEBAR
----------------------------------------------------------------------------- */
.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1000;
    padding: 1rem;
    transition: transform var(--transition-speed);
    overflow-y: auto;
}

.logo-container {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 0.5rem;
    margin-bottom: 1rem;
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.nav-header {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
    padding: 0 0.75rem;
    margin-bottom: 0.5rem;
    display: block;
}

.nav-list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    transition: all 0.2s;
    font-weight: 500;
}

.nav-link:hover,
.nav-link.active {
    background-color: rgba(59, 130, 246, 0.1);
    color: var(--primary-color);
}

.nav-link i {
    width: 1.5rem;
    font-size: 1rem;
}

.nav-link span {
    flex: 1;
}

.nav-link .arrow {
    width: auto;
    font-size: 0.8rem;
}

.submenu {
    padding-left: 2.25rem;
    margin-top: 0.25rem;
    display: none;
}

/* Active submenu logic handled by JS now, but keeping helper class */
.submenu.show {
    display: block;
}

.submenu a {
    display: block;
    padding: 0.5rem 0;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.submenu a.active-sub {
    color: var(--primary-color);
}

.submenu a:hover {
    color: var(--primary-color);
}

/* -----------------------------------------------------------------------------
   4. MAIN CONTENT
----------------------------------------------------------------------------- */
.main-content {
    margin-left: var(--sidebar-width);
    padding: 2rem;
    min-height: 100vh;
    transition: margin-left var(--transition-speed);
}

/* Header */
.top-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2rem;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    transition: background-color 0.2s;
    position: relative;
}

.icon-btn:hover {
    background-color: rgba(0, 0, 0, 0.05);
    color: var(--text-primary);
}

.breadcrumb {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.breadcrumb a {
    color: var(--text-secondary);
    font-weight: 500;
}

.breadcrumb span {
    margin: 0 0.5rem;
    color: var(--text-muted);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.notification-btn .badge {
    position: absolute;
    top: 0;
    right: 0;
    background-color: var(--primary-color);
    color: white;
    width: 18px;
    height: 18px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.65rem;
    border: 2px solid var(--bg-body);
}

.user-profile .avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
}

/* Dashboard Content */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 2rem;
}

.page-title h2 {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
}

.breadcrumb-sub {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.page-actions {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.date-picker-trigger {
    background: var(--bg-card);
    padding: 0.6rem 1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    box-shadow: var(--shadow-sm);
}

.btn {
    padding: 0.6rem 1.2rem;
    border-radius: var(--radius-md);
    border: none;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: filter 0.2s;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    filter: brightness(1.1);
}

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
}

/* Grid System */
.grid-row {
    display: grid;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.top-cards {
    grid-template-columns: repeat(3, 1fr);
}

.middle-section {
    grid-template-columns: 2fr 1fr;
}

.bottom-section {
    grid-template-columns: repeat(3, 1fr);
}

/* Cards */
.card {
    background-color: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
}

.card-header {
    margin-bottom: 1.5rem;
}

.card-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.card-header .subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.value-large {
    font-size: 1.75rem;
    font-weight: 700;
    margin-top: 0.5rem;
}

.performance-card .card-body {
    justify-content: space-between;
}

.performance-info {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.info-group {
    display: flex;
    flex-direction: column;
}

.info-group .label {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.info-group .value {
    font-size: 1.25rem;
    font-weight: 700;
    margin-top: 0.25rem;
}

.circular-chart {
    position: relative;
    width: 100px;
    height: 100px;
}

.circular-chart-svg {
    display: block;
    margin: 0 auto;
    max-width: 100%;
    max-height: 100%;
}

.circle-bg {
    fill: none;
    stroke: #eee;
    stroke-width: 3.8;
}

.circle {
    fill: none;
    stroke-width: 2.8;
    stroke-linecap: round;
    stroke: var(--primary-color);
    animation: progress 1s ease-out forwards;
}

.percentage {
    fill: var(--text-primary);
    font-family: sans-serif;
    font-weight: bold;
    font-size: 0.5em;
    text-anchor: middle;
}

@keyframes progress {
    0% {
        stroke-dasharray: 0 100;
    }
}

.overview-list {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.overview-item {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.icon-box {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.25rem;
}

.overview-details .amount {
    font-size: 1.1rem;
    font-weight: 700;
}

.overview-details .label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.product-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.product-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.product-img {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    object-fit: cover;
}

.product-info h4 {
    font-size: 0.95rem;
    margin-bottom: 0.25rem;
}

.product-info .code {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.product-rating {
    margin-left: auto;
    text-align: right;
}

.stars {
    font-size: 0.8rem;
    margin-bottom: 0.25rem;
}

.reviews {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* -----------------------------------------------------------------------------
   5. DATA TABLES (CRM, Invoice, Analytics)
----------------------------------------------------------------------------- */
.table-responsive {
    overflow-x: auto;
    width: 100%;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.table th,
.table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.table th {
    font-weight: 600;
    color: var(--text-muted);
    background-color: rgba(0, 0, 0, 0.02);
}

.table tr:last-child td {
    border-bottom: none;
}

.table tr:hover {
    background-color: rgba(0, 0, 0, 0.01);
}

.user-info-cell {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-info-cell img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
}

.status {
    padding: 0.25rem 0.6rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
}

.status.paid,
.status.completed,
.status.active {
    background-color: rgba(16, 185, 129, 0.1);
    color: var(--success-color);
}

.status.pending,
.status.progress {
    background-color: rgba(245, 158, 11, 0.1);
    color: var(--warning-color);
}

.status.failed,
.status.cancelled,
.status.inactive {
    background-color: rgba(239, 68, 68, 0.1);
    color: var(--danger-color);
}

/* -----------------------------------------------------------------------------
   6. APP: CHAT & EMAIL
----------------------------------------------------------------------------- */
.app-container {
    display: flex;
    height: calc(100vh - 180px);
    /* Adjust based on header */
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.app-sidebar {
    width: 300px;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.app-search {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.app-search input {
    width: 100%;
    padding: 0.6rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-body);
    color: var(--text-primary);
}

.app-list {
    flex: 1;
    overflow-y: auto;
}

.app-list-item {
    padding: 1rem;
    display: flex;
    gap: 0.75rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.2s;
}

.app-list-item:hover,
.app-list-item.active {
    background-color: rgba(59, 130, 246, 0.05);
}

.app-list-item img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

.item-info {
    flex: 1;
    min-width: 0;
}

.item-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.25rem;
}

.item-name {
    font-weight: 600;
    font-size: 0.9rem;
}

.item-time {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.item-preview {
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-body);
}

.chat-header {
    background: var(--bg-card);
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-body {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message {
    max-width: 70%;
    padding: 0.75rem 1rem;
    border-radius: 1rem;
    font-size: 0.9rem;
    line-height: 1.4;
    position: relative;
    border: 1px solid transparent;
}

.message.received {
    background: var(--bg-card);
    align-self: flex-start;
    border-bottom-left-radius: 2px;
    border-color: var(--border-color);
}

.message.sent {
    background: var(--primary-color);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 2px;
}

.chat-footer {
    padding: 1rem;
    background: var(--bg-card);
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 0.5rem;
}

.chat-input {
    flex: 1;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-body);
    color: var(--text-primary);
}

/* -----------------------------------------------------------------------------
   7. APP: KANBAN
----------------------------------------------------------------------------- */
.kanban-board {
    display: flex;
    gap: 1.5rem;
    overflow-x: auto;
    height: calc(100vh - 180px);
    padding-bottom: 1rem;
}

.kanban-column {
    min-width: 300px;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.kanban-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.kanban-items {
    padding: 1rem;
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.kanban-card {
    background: var(--bg-body);
    padding: 1rem;
    border-radius: var(--radius-md);
    cursor: grab;
    border: 1px solid transparent;
    transition: transform 0.2s, box-shadow 0.2s;
}

.kanban-card:hover {
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.card-tags {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.tag {
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.1);
}

.card-title {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

.card-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* -----------------------------------------------------------------------------
   8. APP: CALENDAR
----------------------------------------------------------------------------- */
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
    background: var(--border-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.cal-day-header {
    background: var(--bg-card);
    padding: 1rem;
    text-align: center;
    font-weight: 600;
}

.cal-day {
    background: var(--bg-card);
    min-height: 120px;
    padding: 0.5rem;
    position: relative;
    transition: background 0.2s;
}

.cal-day:hover {
    background: rgba(0, 0, 0, 0.01);
}

.cal-date {
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
    display: block;
    font-weight: 500;
}

.cal-current-month {
    color: var(--text-primary);
}

.cal-other-month {
    color: var(--text-muted);
    background: rgba(0, 0, 0, 0.02);
}

.cal-event {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    margin-bottom: 0.25rem;
    border-radius: 4px;
    color: white;
    cursor: pointer;
    background-color: var(--primary-color);
}

.cal-event.urgent {
    background-color: var(--danger-color);
}

.cal-event.meeting {
    background-color: var(--warning-color);
}

/* -----------------------------------------------------------------------------
   9. FORMS & AUTH
----------------------------------------------------------------------------- */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-body);
}

.auth-card {
    width: 100%;
    max-width: 400px;
    padding: 2.5rem;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    text-align: center;
    border: 1px solid var(--border-color);
}

.auth-logo {
    font-size: 2rem;
    margin-bottom: 1.5rem;
    display: block;
}

.form-group {
    text-align: left;
    margin-bottom: 1.5rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    font-weight: 500;
}

.form-control {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-body);
    color: var(--text-primary);
    transition: border-color 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
}

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}

/* -----------------------------------------------------------------------------
   10. DROPDOWNS & UTILS
----------------------------------------------------------------------------- */
.dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    width: 180px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    display: none;
    margin-top: 0.5rem;
    padding: 0.5rem 0;
}

.dropdown-menu.show {
    display: block;
    animation: fadeIn 0.1s ease-out;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.2s;
}

.dropdown-item:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--primary-color);
}

.dropdown-divider {
    height: 1px;
    background: var(--border-color);
    margin: 0.5rem 0;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

footer {
    margin-top: 2rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.dropdown-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    padding: 0.4rem 0.8rem;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    cursor: pointer;
}

/* -----------------------------------------------------------------------------
   11. TOAST NOTIFICATIONS & TOGGLES
----------------------------------------------------------------------------- */
#toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 9999;
}

.toast {
    background: var(--bg-card);
    color: var(--text-primary);
    padding: 1rem 1.5rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    border-left: 4px solid var(--primary-color);
    animation: slideIn 0.3s ease-out forwards;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 250px;
}

.toast-success {
    border-left-color: var(--success-color);
}

.toast-error {
    border-left-color: var(--danger-color);
}

.toast i {
    font-size: 1.2rem;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
    }
}

/* Toggle Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--border-color);
    transition: .4s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    box-shadow: var(--shadow-sm);
}

input:checked+.slider {
    background-color: var(--primary-color);
}

input:focus+.slider {
    box-shadow: 0 0 1px var(--primary-color);
}

input:checked+.slider:before {
    transform: translateX(20px);
}

.slider.round {
    border-radius: 34px;
}

.slider.round:before {
    border-radius: 50%;
}