/*
 * App-wide Stylesheet
 * Version: 2.0
 * Description: A complete and modern redesign for the application.
 */

:root {
    color-scheme: light;
    font-family: 'Cairo', 'Tajawal', sans-serif;
    --primary: #0b2545; /* deep navy */
    --primary-dark: #071830;
    --accent: #1976d2; /* A brighter blue for accents */
    --surface: #ffffff;
    --surface-alt: #f8fafc;
    --background: #f1f5f9;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --radius: 12px;
    --shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
}

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

body {
    background-color: var(--background);
    color: var(--text-main);
    font-size: 15px;
    line-height: 1.6;
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: color 0.2s;
}
a:hover {
    color: var(--primary);
    text-decoration: underline;
}

/* Layout */
.app-shell {
    display: flex;
    min-height: 100vh;
}
.sidebar {
    --sidebar-width: 260px;
    --sidebar-padding: 24px;
    flex: 0 0 var(--sidebar-width);
    width: var(--sidebar-width);
    background: var(--primary-dark);
    color: #fff;
    padding: var(--sidebar-padding);
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease, padding 0.3s ease, transform 0.3s ease, opacity 0.2s ease;
    overflow-y: auto;
}
.app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
}
.dashboard-header {
    background: var(--surface);
    padding: 16px clamp(16px, 4vw, 32px);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    flex-wrap: wrap;
}
.dashboard-header h1 {
    font-size: 24px;
    font-weight: 700;
    margin: 0;
}
.welcome-note {
    color: var(--text-muted);
    font-size: 14px;
    margin-top: 4px;
}
.page-header-titles {
    flex: 1 1 220px;
    min-width: 200px;
}

.dashboard-header-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    flex: 0 0 auto;
    flex-wrap: wrap;
}

.sidebar-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    padding: 8px 12px;
    font-size: 20px;
    line-height: 1;
}

.app-shell.sidebar-collapsed .sidebar {
    flex-basis: 0;
    width: 0;
    padding: 0;
    opacity: 0;
    transform: translateX(100%);
    pointer-events: none;
    overflow: hidden;
}

.app-shell.sidebar-collapsed .app-main {
    flex: 1 1 auto;
}

.logout-form {
    margin: 0;
    display: flex;
    align-items: center;
}

.logout-form .logout-btn {
    flex: 0 0 auto;
}

.dashboard-content {
    padding: clamp(20px, 4vw, 32px);
    flex: 1;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    align-self: center;
}

/* Sidebar */
.sidebar-user {
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-user-greeting {
    font-size: 14px;
    opacity: 0.7;
}
.sidebar-user-name {
    display: block;
    font-size: 16px;
    font-weight: 600;
}
.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 16px;
}
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    color: rgba(255,255,255,0.8);
    padding: 12px 16px;
    border-radius: 8px;
    font-weight: 500;
    transition: all 0.2s ease-in-out;
}
.sidebar-link:hover, .sidebar-link.active {
    background: var(--accent);
    color: #fff;
    text-decoration: none;
    transform: translateX(4px);
    box-shadow: 0 4px 10px rgba(25, 118, 210, 0.3);
}

.sidebar-link::before {
    content: '';
    display: inline-block;
    width: 20px;
    height: 20px;
    background-color: currentColor;
    mask-repeat: no-repeat;
    mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    -webkit-mask-size: contain;
    flex-shrink: 0;
}

/* Icons for sidebar links */
a[href*="dashboard.php"]::before { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='currentColor'%3E%3Cpath d='M3 13h8V3H3v10zm0 8h8v-6H3v6zm10 0h8V11h-8v10zm0-18v6h8V3h-8z'/%3E%3C/svg%3E"); }
a[href*="inventory.php"]::before { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='currentColor'%3E%3Cpath d='M20 2H4c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-5 14H9v-2h6v2zm3-4H6v-2h12v2zm0-4H6V6h12v2z'/%3E%3C/svg%3E"); }
a[href*="clients.php"]::before { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='currentColor'%3E%3Cpath d='M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z'/%3E%3C/svg%3E"); }
a[href*="suppliers.php"]::before { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='currentColor'%3E%3Cpath d='M16.5 12c1.38 0 2.5-1.12 2.5-2.5S17.88 7 16.5 7C15.12 7 14 8.12 14 9.5s1.12 2.5 2.5 2.5zM9 11c1.66 0 3-1.34 3-3s-1.34-3-3-3-3 1.34-3 3 1.34 3 3 3zm7.5 3c-1.83 0-5.5.92-5.5 2.75V19h11v-2.25c0-1.83-3.67-2.75-5.5-2.75zM9 13c-2.33 0-7 1.17-7 3.5V19h7v-2.25c0-.85.33-2.34 2.37-3.41C10.5 13.1 9.66 13 9 13z'/%3E%3C/svg%3E"); }
a[href*="cash.php"]::before { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='currentColor'%3E%3Cpath d='M21 18v1c0 1.1-.9 2-2 2H5c-1.11 0-2-.9-2-2V5c0-1.1.89-2 2-2h14c1.1 0 2 .9 2 2v1h-9c-1.11 0-2 .9-2 2v8c0 1.1.89 2 2 2h9zm-9-2h10V8H12v8zm4-2.5c-.83 0-1.5-.67-1.5-1.5s.67-1.5 1.5-1.5 1.5.67 1.5 1.5-.67 1.5-1.5 1.5z'/%3E%3C/svg%3E"); }
a[href*="reports.php"]::before { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='currentColor'%3E%3Cpath d='M8 10h.01M12 10h.01M16 10h.01M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-5 14H7v-2h7v2zm3-4H7v-2h10v2zm0-4H7V7h10v2z'/%3E%3C/svg%3E"); }
a[href*="settings.php"]::before { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='currentColor'%3E%3Cpath d='M19.43 12.98c.04-.32.07-.64.07-.98s-.03-.66-.07-.98l2.11-1.65c.19-.15.24-.42.12-.64l-2-3.46c-.12-.22-.39-.3-.61-.22l-2.49 1c-.52-.4-1.08-.73-1.69-.98l-.38-2.65C14.46 2.18 14.25 2 14 2h-4c-.25 0-.46.18-.49.42l-.38 2.65c-.61.25-1.17.59-1.69.98l-2.49-1c-.23-.09-.49 0-.61.22l-2 3.46c-.13.22-.07.49.12.64l2.11 1.65c-.04.32-.07.65-.07.98s.03.66.07.98l-2.11 1.65c-.19.15-.24.42-.12.64l2 3.46c.12.22.39.3.61.22l2.49-1c.52.4 1.08.73 1.69.98l.38 2.65c.03.24.24.42.49.42h4c.25 0 .46-.18.49-.42l.38-2.65c.61-.25 1.17-.59 1.69-.98l2.49 1c.23.09.49 0 .61.22l2-3.46c.12-.22-.07-.49-.12-.64l-2.11-1.65zM12 15.5c-1.93 0-3.5-1.57-3.5-3.5s1.57-3.5 3.5-3.5 3.5 1.57 3.5 3.5-1.57 3.5-3.5 3.5z'/%3E%3C/svg%3E"); }
}
.sidebar-group summary {
    cursor: pointer;
    list-style: none; /* Remove default marker */
}
.sidebar-group summary::-webkit-details-marker {
    display: none; /* For Chrome/Safari */
}
.sidebar-group summary::before {
    content: '';
    display: inline-block;
    width: 20px;
    height: 20px;
    background-color: currentColor;
    mask-repeat: no-repeat;
    mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    -webkit-mask-size: contain;
    flex-shrink: 0;
}
.sidebar-subnav {
    margin-top: 4px;
    padding-right: 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.sidebar-subnav a {
    color: rgba(255,255,255,0.7);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 14px;
}
.sidebar-subnav a:hover, .sidebar-subnav a.active {
    background: rgba(0,0,0,0.2);
    color: #fff;
    text-decoration: none;
}
summary[class*="sales"]::before { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='currentColor'%3E%3Cpath d='M11.8 10.9c-2.27-.59-3-1.2-3-2.15 0-1.09 1.01-1.85 2.7-1.85 1.78 0 2.44.85 2.5 2.1h2.21c-.07-1.72-1.12-3.3-3.21-3.81V3h-3v2.16c-1.94.42-3.5 1.68-3.5 3.61 0 2.31 1.91 3.46 4.7 4.13 2.5.6 3 1.48 3 2.41 0 .69-.49 1.79-2.7 1.79-2.06 0-2.87-.92-2.98-2.1h-2.2c.12 2.19 1.76 3.42 3.68 3.83V21h3v-2.15c1.95-.37 3.5-1.5 3.5-3.55 0-2.84-2.43-3.81-4.7-4.4z'/%3E%3C/svg%3E"); }
summary[class*="purchase"]::before { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='currentColor'%3E%3Cpath d='M20 4H4c-1.11 0-1.99.89-1.99 2L2 18c0 1.11.89 2 2 2h16c1.11 0 2-.89 2-2V6c0-1.11-.89-2-2-2zm0 14H4v-6h16v6zm0-10H4V6h16v2z'/%3E%3C/svg%3E"); }
summary[class*="expenses"]::before { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='currentColor'%3E%3Cpath d='M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-2 10H7v-2h10v2z'/%3E%3C/svg%3E"); }

/* Settings Page Tabs */
.settings-nav {
    display: flex;
    gap: 8px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 24px;
}
.settings-nav a {
    padding: 10px 20px;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 3px solid transparent;
    transition: color 0.2s, border-color 0.2s;
    text-decoration: none;
}
.settings-nav a.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* Components */
.panel {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 24px;
    overflow: hidden;
}
.panel-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    font-size: 18px;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.panel-body {
    padding: 24px;
}

.table-wrapper {
    width: 100%;
    overflow-x: auto;
}

/* --- Responsive Sidebar (mobile) --- */
@media (max-width: 992px) {
    .sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        right: 0; /* RTL: open from the right */
        z-index: 999;
        transform: translateX(100%);
        box-shadow: var(--shadow-lg);
    }
    .sidebar.is-open {
        transform: translateX(0%);
    }
    .sidebar-toggle-btn {
        margin-inline-start: 8px;
    }
}

/* --- Utility visibility helpers --- */
@media (max-width: 992px) {
    .hide-mobile { display: none !important; }
}
@media (min-width: 993px) {
    .hide-desktop { display: none !important; }
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 24px;
    margin-bottom: 32px;
}

.dashboard-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}

.dashboard-action {
    --action-from: #2563eb;
    --action-to: #1e40af;
    --action-glow: rgba(37, 99, 235, 0.35);
    background: linear-gradient(135deg, var(--action-from), var(--action-to));
    border-radius: 18px;
    border: none;
    padding: 18px 20px;
    display: flex;
    align-items: center;
    gap: 14px;
    text-decoration: none;
    color: #fff;
    box-shadow: 0 14px 30px rgba(15, 23, 42, 0.18), 0 8px 18px var(--action-glow);
    transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
    position: relative;
    overflow: hidden;
    min-height: 92px;
    isolation: isolate;
}

.dashboard-action::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        radial-gradient(120px 90px at 88% 18%, rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0) 60%),
        radial-gradient(140px 110px at 10% 85%, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0) 70%);
    opacity: 0.9;
    pointer-events: none;
    z-index: 0;
}

.dashboard-action:hover {
    transform: translateY(-4px) scale(1.01);
    box-shadow: 0 18px 36px rgba(15, 23, 42, 0.22), 0 10px 24px var(--action-glow);
    filter: brightness(1.02);
    text-decoration: none;
}

.dashboard-action .action-emoji {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
    flex: 0 0 48px;
    z-index: 1;
}

.dashboard-action .action-content {
    display: flex;
    flex-direction: column;
    gap: 2px;
    z-index: 1;
}

.dashboard-action .action-title {
    font-size: 17px;
    font-weight: 700;
    color: #fff;
}

.dashboard-action .action-subtitle {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.85);
}

.dashboard-action .action-arrow {
    margin-inline-start: auto;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: #fff;
    background: rgba(255, 255, 255, 0.18);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.3);
    transition: transform 0.2s ease, background 0.2s ease;
    z-index: 1;
}

.dashboard-action:hover .action-arrow {
    transform: translateY(-2px);
    background: rgba(255, 255, 255, 0.28);
}

.dashboard-action.action-sale .action-emoji {
    background: rgba(255, 255, 255, 0.2);
}

.dashboard-action.action-purchase .action-emoji {
    background: rgba(255, 255, 255, 0.2);
}

.dashboard-action.action-expense .action-emoji {
    background: rgba(255, 255, 255, 0.2);
}

.dashboard-action.action-sale {
    --action-from: #16a34a;
    --action-to: #0f766e;
    --action-glow: rgba(34, 197, 94, 0.35);
}

.dashboard-action.action-purchase {
    --action-from: #2563eb;
    --action-to: #1e3a8a;
    --action-glow: rgba(37, 99, 235, 0.35);
}

.dashboard-action.action-expense {
    --action-from: #f97316;
    --action-to: #c2410c;
    --action-glow: rgba(249, 115, 22, 0.35);
}
.stat-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}
.stat-title {
    color: var(--text-muted);
    font-size: 14px;
    margin-bottom: 8px;
}
.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--primary);
}
.stat-trend {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 8px;
}

/* Forms */
label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    font-size: 14px;
}
input, select, textarea {
    width: 100%;
    padding: 12px 14px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface-alt);
    font-size: 15px;
    transition: border-color 0.2s, box-shadow 0.2s;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(25, 118, 210, 0.12);
    background: var(--surface);
}
.form-grid, .grid-two {
    display: grid;
    gap: 16px 20px;
}
.grid-two {
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}
.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 16px;
    align-items: center;
}

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}
/* Inline Filters (for reports page) */
.filters-inline {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: flex-end;
}
.filters-inline .filter-item {
    flex: 1 1 180px; /* Grow, shrink, with a base width */
    min-width: 180px;
}
.filters-inline label {
    font-size: 13px;
    margin-bottom: 6px;
}
.filters-inline input,
.filters-inline select {
    padding: 8px 10px;
    font-size: 14px;
}
.filters-inline .filter-actions {
    display: flex;
    gap: 10px;
}
.filters-inline .primary-btn,
.filters-inline .secondary-btn {
    padding: 8px 16px;
}

/* Collapsible sections (used in inventory, clients, etc.) */
.collapsible {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.35s ease-out, padding 0.35s ease-out, margin 0.35s ease-out;
    padding-top: 0;
    padding-bottom: 0;
    margin-top: 0;
}
.collapsible.is-open {
    max-height: 1000px; /* Large enough for content */
    padding-top: 24px;
    padding-bottom: 24px;
    margin-top: 16px;
}

/* Permissions Grid */
.permissions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 24px;
    margin-top: 16px;
}
.permission-group-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}
.permission-item {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    cursor: pointer;
}
.permission-item input[type="checkbox"] {
    width: auto;
}

/* Buttons */
.primary-btn, .secondary-btn {
    border: none;
    border-radius: 8px;
    padding: 12px 20px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    display: inline-block;
    text-align: center;
}
.primary-btn {
    background: var(--primary);
    color: #fff;
}
.primary-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    color: #fff;
}
.secondary-btn {
    background: var(--surface-alt);
    color: var(--text-main);
    border: 1px solid var(--border);
}
.secondary-btn:hover {
    background: var(--surface);
    border-color: var(--accent);
    color: var(--accent);
}

/* Tables */
.table-wrapper {
    overflow-x: auto;
}
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
th, td {
    padding: 14px 16px;
    text-align: right;
    border-bottom: 1px solid var(--border);
}
thead th {
    background: var(--surface-alt);
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 12px;
    letter-spacing: 0.5px;
}
tbody tr:hover {
    background-color: var(--surface-alt);
}
.table-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}
.action-btn {
    font-size: 13px;
    padding: 4px 10px;
    border-radius: 6px;
}
.action-edit { background: rgba(25, 118, 210, 0.1); color: #1976D2; }
.action-delete { background: rgba(211, 47, 47, 0.1); color: #D32F2F; cursor: pointer; border: none; font-family: inherit; }
.action-view { background: rgba(100, 116, 139, 0.1); color: #475569; }

/* Purchases table */
.purchase-table {
    border-collapse: separate;
    border-spacing: 0 10px;
    table-layout: fixed;
}
.purchase-table thead th {
    background: transparent;
    border-bottom: none;
}
.purchase-table th,
.purchase-table td {
    padding: 10px 12px;
    white-space: normal;
    overflow-wrap: anywhere;
}
.purchase-table tbody tr {
    background: var(--surface);
    box-shadow: var(--shadow);
}
.purchase-table tbody td {
    background: var(--surface);
    border-bottom: none;
}
.purchase-table tbody tr:hover td {
    background: var(--surface-alt);
}
.purchase-table tbody tr td:first-child {
    border-top-right-radius: 10px;
    border-bottom-right-radius: 10px;
}
.purchase-table tbody tr td:last-child {
    border-top-left-radius: 10px;
    border-bottom-left-radius: 10px;
}
.order-number {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface-alt);
    font-size: 12px;
    font-weight: 600;
    color: var(--primary);
}
.pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 10px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface-alt);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-main);
}
.pill-muted {
    color: var(--text-muted);
}
.cell-amount {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.purchase-table .cell-amount {
    white-space: normal;
}
.amount-due {
    color: #b45309;
    font-weight: 600;
}
.amount-ok {
    color: #15803d;
    font-weight: 600;
}
.status-pill {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    border: 1px solid transparent;
}
.status-pending {
    background: rgba(234, 179, 8, 0.15);
    color: #a16207;
    border-color: rgba(234, 179, 8, 0.35);
}
.status-partial {
    background: rgba(59, 130, 246, 0.12);
    color: #1d4ed8;
    border-color: rgba(59, 130, 246, 0.3);
}
.status-paid {
    background: rgba(34, 197, 94, 0.12);
    color: #15803d;
    border-color: rgba(34, 197, 94, 0.3);
}
.purchase-table .table-actions {
    flex-wrap: wrap;
    gap: 6px;
}
.purchase-table .action-btn {
    font-size: 12px;
    padding: 4px 8px;
}

@media (max-width: 900px) {
    .purchase-table {
        min-width: 0;
        border-spacing: 0;
    }
    .purchase-table thead {
        display: none;
    }
    .purchase-table,
    .purchase-table tbody,
    .purchase-table tr,
    .purchase-table td {
        display: block;
        width: 100%;
    }
    .purchase-table tbody tr {
        margin-bottom: 12px;
        border-radius: 12px;
        overflow: hidden;
    }
    .purchase-table tbody td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        padding: 10px 14px;
        border-bottom: 1px dashed var(--border);
    }
    .purchase-table tbody td:last-child {
        border-bottom: none;
    }
    .purchase-table tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-muted);
    }
    .table-actions {
        justify-content: flex-start;
        flex-wrap: wrap;
    }
}

/* Compact form inside a table cell */
.table-form-inline {
    margin-top: 8px;
}
.table-form-inline select,
.table-form-inline input {
    padding: 6px 8px;
    font-size: 13px;
    flex: 1;
}
.table-form-inline button {
    padding: 6px 12px;
    font-size: 13px;
    flex-shrink: 0;
    height: 35px; /* Match input height */
}

/* Auth Page */
.auth-card {
    max-width: 400px;
    margin: 40px auto;
    padding: 40px;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    text-align: center;
}
.auth-card h1 { font-size: 28px; margin-bottom: 8px; }
.auth-subtitle { color: var(--text-muted); margin-bottom: 32px; }
.field { margin-bottom: 20px; text-align: right; }
.demo-note { font-size: 13px; color: var(--text-muted); margin-top: 24px; }

/* Flash Messages */
.flash {
    padding: 16px;
    margin-bottom: 20px;
    border-radius: 8px;
    border: 1px solid transparent;
}
.flash-error { background-color: #fdeded; border-color: #f9c6c6; color: #5c2121; }
.flash-success { background-color: #e6f4ea; border-color: #bde0c5; color: #1e462a; }

/* Responsive */
@media (max-width: 992px) {
    .dashboard-header {
        padding: 16px;
    }
    .dashboard-header-actions {
        width: 100%;
        justify-content: space-between;
    }
    .dashboard-content {
        padding: 16px;
    }
}

@media (max-width: 600px) {
    .app-shell {
        flex-direction: column;
    }
    .dashboard-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
    .dashboard-header-actions {
        width: 100%;
        justify-content: flex-start;
        gap: 10px;
    }
    .sidebar-toggle-btn {
        order: -1;
    }
    .logout-form {
        width: 100%;
    }
    .logout-form .logout-btn {
        width: 100%;
    }
    .panel {
        border-radius: var(--radius);
    }
    .panel-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    .panel-body {
        padding: 18px;
    }
    .stats-grid {
        grid-template-columns: 1fr;
    }
    .invoice-form-grid {
        grid-template-columns: 1fr;
    }
    .admin-inline-form,
    .filters-inline,
    .actions-inline {
        grid-template-columns: 1fr;
    }
    .table-wrapper {
        margin-bottom: 16px;
    }
}

/* Invoice Create/Edit Pages */
.invoice-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px 24px;
}

.invoice-items-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.invoice-tools {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.invoice-product-search {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
}

.invoice-product-search input {
    min-width: 220px;
}

.invoice-items-panel .panel-body {
    padding: 0;
}

.invoice-items-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.invoice-items-table thead {
    background-color: var(--surface-alt);
}

.invoice-items-table th {
    padding: 12px 16px;
    text-align: right;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 13px;
}

.invoice-items-table td {
    padding: 8px 16px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.invoice-items-table tbody tr:last-child td {
    border-bottom: none;
}

.invoice-items-table td input,
.invoice-items-table td select {
    padding: 8px 10px;
    font-size: 14px;
    border-radius: 6px;
}

.invoice-summary {
    padding: 24px;
    background-color: var(--surface-alt);
    border-top: 1px solid var(--border);
}

.invoice-summary p {
    margin-bottom: 8px;
    font-size: 16px;
}
.invoice-summary p:last-child { margin-bottom: 0; }

@media (max-width: 600px) {
    .invoice-product-search {
        width: 100%;
    }
    .invoice-product-search input {
        flex: 1;
        min-width: 0;
    }
    .dashboard-action {
        padding: 14px 16px;
    }
    .dashboard-action .action-arrow {
        display: none;
    }
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1001;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.5);
    padding-top: 60px;
}

.modal-content {
    background-color: var(--surface);
    margin: 5% auto;
    border-radius: var(--radius);
    width: 90%;
    max-width: 600px;
    box-shadow: var(--shadow-lg);
    animation: animatetop 0.4s;
    overflow: hidden;
}

@keyframes animatetop {
    from {top: -300px; opacity: 0}
    to {top: 0; opacity: 1}
}

.modal-header {
    padding: 16px 24px;
    background-color: var(--primary);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-header h2 { font-size: 20px; }

.modal-body {
    padding: 24px;
}

.modal-footer {
    padding: 16px 24px;
    background-color: var(--surface-alt);
    text-align: left;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.close-btn {
    color: white;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}
.modal-footer .close-btn { color: var(--text-main); font-size: 15px; font-weight: 600; }

.close-btn:hover,
.close-btn:focus {
    color: #bbb;
    text-decoration: none;
}

/* Inventory Page: Warehouse Header */
.warehouse-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}
.warehouse-title h2 {
    margin: 0;
    font-size: 20px;
}
.warehouse-stats {
    display: flex;
    gap: 24px;
    font-size: 14px;
    color: var(--text-muted);
}
.warehouse-actions {
    display: flex;
    gap: 12px;
}
.warehouse-actions .primary-btn, .warehouse-actions .secondary-btn {
    padding: 10px 16px;
    font-size: 14px;
}

.client-name-wrapper {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.client-name-title {
    font-weight: 700;
    font-size: 15px;
    color: var(--text-main);
}

.client-sales-list {
    list-style: none;
    margin: 4px 0 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.client-sales-list li {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    background: #f8fafc;
    border: 1px solid rgba(148, 163, 184, 0.3);
    border-radius: 10px;
    padding: 5px 8px;
    font-size: 12px;
    color: #0f172a;
}

.client-sale-date {
    font-weight: 600;
}

.client-sale-amount {
    color: #0f172a;
}

.client-sale-remaining {
    color: #b91c1c;
    font-weight: 600;
}

.client-sale-status {
    color: #475569;
}

.client-sale-link {
    margin-inline-start: auto;
    font-weight: 600;
    color: var(--accent);
    font-size: 12px;
}

.client-sales-list li:hover .client-sale-link {
    text-decoration: underline;
}

.item-product-cell {
    display: flex;
    align-items: center;
    gap: 6px;
}

.serial-btn {
    border: 1px solid rgba(59, 130, 246, 0.35);
    background: rgba(59, 130, 246, 0.12);
    color: #1d4ed8;
    border-radius: 8px;
    padding: 4px 8px;
    font-size: 11px;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.serial-btn:hover {
    background: rgba(59, 130, 246, 0.2);
    border-color: rgba(59, 130, 246, 0.6);
}

.serial-count-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    padding: 2px 6px;
    border-radius: 999px;
    background: rgba(22, 163, 74, 0.18);
    color: #166534;
    font-size: 11px;
    font-weight: 600;
}

.serial-count-badge[hidden] {
    display: none;
}

.autocomplete-suggestions {
    position: absolute;
    inset-inline-start: 0;
    inset-inline-end: 0;
    top: calc(100% + 4px);
    z-index: 40;
    background: #fff;
    border: 1px solid rgba(148, 163, 184, 0.45);
    border-radius: 10px;
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.12);
    display: none;
    max-height: 220px;
    overflow-y: auto;
    padding: 4px;
}

.autocomplete-suggestions.is-visible {
    display: block;
}

.autocomplete-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    color: #0f172a;
    transition: background 0.12s ease;
}

.autocomplete-item:hover,
.autocomplete-item.is-active {
    background: rgba(59, 130, 246, 0.12);
}

.autocomplete-item.is-empty {
    cursor: default;
    justify-content: center;
    color: #64748b;
}

.autocomplete-name {
    font-weight: 600;
}

.autocomplete-meta {
    margin-inline-start: 12px;
    font-size: 12px;
    color: #64748b;
}

.serial-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.serial-modal-backdrop.is-visible {
    display: flex;
}

.serial-modal {
    background: #ffffff;
    width: min(520px, 92%);
    border-radius: 18px;
    box-shadow: 0 28px 60px rgba(15, 23, 42, 0.2);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.serial-modal h3 {
    margin: 0;
    font-size: 18px;
    color: #0f172a;
}

.serial-modal textarea {
    width: 100%;
    min-height: 160px;
    border: 1px solid rgba(148, 163, 184, 0.45);
    border-radius: 12px;
    padding: 10px 12px;
    font-family: var(--admin-font, inherit);
    font-size: 13px;
    resize: vertical;
}

.serial-modal textarea:focus {
    outline: none;
    border-color: rgba(59, 130, 246, 0.6);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.18);
}

.serial-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}
