/**
 * 7GEN Dashboard - Base Styles
 * Clean, minimal, functional.
 */

:root {
    /* Colors - Dark Mode (default) */
    --bg-primary: #0f1419;
    --bg-secondary: #1a1f26;
    --bg-tertiary: #252b33;
    --text-primary: #e7e9ea;
    --text-secondary: #8b98a5;
    --accent: #1d9bf0;
    --success: #00ba7c;
    --warning: #ff9800;
    --error: #f4212e;
    --shadow-color: rgba(0, 0, 0, 0.3);
    --border-color: #2f3336;
    
    /* Role colors (from spec) */
    --role-sales: #1d9bf0;      /* 🔵 */
    --role-designer: #00ba7c;    /* 🟢 */
    --role-production: #ff7a00;  /* 🟠 */
    --role-factory: #8b4513;     /* 🟤 */
    --role-manager: #f4212e;     /* 🔴 */
    --role-admin: #9333ea;       /* 🟣 */
    --role-superadmin: #374151;  /* ⚫ */
    --role-client: #6b7280;      /* ⚪ */
    
    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    
    /* Typography */
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-size-sm: 13px;
    --font-size-md: 15px;
    --font-size-lg: 18px;
    --font-size-xl: 24px;
    
    /* Borders */
    --border-radius: 8px;
}

/* Light Mode (opt-in) */
[data-theme="light"] {
    --bg-primary: #ffffff;
    --bg-secondary: #f7f9fa;
    --bg-tertiary: #eff3f4;
    --text-primary: #0f1419;
    --text-secondary: #536471;
    --border-color: #e1e4e8;
    --shadow-color: rgba(0, 0, 0, 0.1);
}

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

/* Form element defaults - ensure dark theme applies everywhere */
input,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="tel"],
input[type="url"],
input[type="date"],
select,
textarea {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    color: var(--text-primary);
    font-family: inherit;
    font-size: inherit;
}

/* Native date picker icon is black by default; invert it in dark mode so it
   sits readably on the dark input background. */
[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator,
[data-theme="dark"] input[type="time"]::-webkit-calendar-picker-indicator,
[data-theme="dark"] input[type="datetime-local"]::-webkit-calendar-picker-indicator,
[data-theme="dark"] input[type="month"]::-webkit-calendar-picker-indicator,
[data-theme="dark"] input[type="week"]::-webkit-calendar-picker-indicator {
    filter: invert(1);
    opacity: 0.7;
    cursor: pointer;
}
[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator:hover,
[data-theme="dark"] input[type="time"]::-webkit-calendar-picker-indicator:hover,
[data-theme="dark"] input[type="datetime-local"]::-webkit-calendar-picker-indicator:hover,
[data-theme="dark"] input[type="month"]::-webkit-calendar-picker-indicator:hover,
[data-theme="dark"] input[type="week"]::-webkit-calendar-picker-indicator:hover {
    opacity: 1;
}

html, body {
    height: 100%;
    font-family: var(--font-family);
    font-size: var(--font-size-md);
    background: var(--bg-primary);
    color: var(--text-primary);
}

/* Login Page */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-lg);
}

.login-box {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: var(--space-xl);
    width: 100%;
    max-width: 400px;
}

.login-box h1 {
    font-size: var(--font-size-xl);
    margin-bottom: var(--space-xs);
}

.login-box .tagline {
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
    margin-bottom: var(--space-lg);
}

.form-group {
    margin-bottom: var(--space-md);
}

.form-group label {
    display: block;
    margin-bottom: var(--space-xs);
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    color: var(--text-primary);
    font-size: var(--font-size-md);
    box-sizing: border-box;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent);
}

/* Radio button group */
.radio-group {
    display: flex;
    gap: var(--space-lg);
}
.radio-label {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    cursor: pointer;
    font-size: var(--font-size-md);
}
.radio-label input[type="radio"] {
    width: 18px;
    height: 18px;
    margin: 0;
    cursor: pointer;
    accent-color: var(--accent);
}

.form-group select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238b98a5' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--space-md) center;
    padding-right: var(--space-xl);
}

.form-group textarea {
    min-height: 100px;
    resize: vertical;
}

.form-group input[type="color"] {
    padding: 4px;
    height: 42px;
    cursor: pointer;
}

.error-message {
    background: rgba(244, 33, 46, 0.1);
    border: 1px solid var(--error);
    color: var(--error);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--border-radius);
    margin-bottom: var(--space-md);
    font-size: var(--font-size-sm);
}

/* Buttons */
.btn {
    display: inline-block;
    padding: var(--space-sm) var(--space-lg);
    border: none;
    border-radius: var(--border-radius);
    font-size: var(--font-size-md);
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: opacity 0.2s;
}

.btn:hover {
    opacity: 0.9;
}

.btn-primary {
    background: var(--accent);
    color: white;
    width: 100%;
}

.modal-actions .btn-primary {
    width: auto;
}

.btn-small {
    padding: var(--space-xs) var(--space-sm);
    font-size: var(--font-size-sm);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.btn-success {
    background: #28a745;
    color: white;
    border-color: #28a745;
}

.btn-success:hover {
    background: #218838;
    border-color: #1e7e34;
}

/* Dashboard Header */
.dashboard-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md) var(--space-lg);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
}

.dashboard-header h1 {
    font-size: var(--font-size-lg);
    font-weight: 700;
}

.header-logo {
    height: 32px;
    width: auto;
}

/* Invert logo for light mode (SVG is white by default) */
[data-theme="light"] .header-logo {
    filter: invert(1);
}

.header-right {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

/* Dashboard Footer */
.dashboard-footer {
    display: flex;
    justify-content: center;
    padding: var(--space-lg) var(--space-md);
    margin-top: var(--space-lg);
}

.user-name {
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
}

/* Role Switcher */
.role-switcher {
    display: flex;
    gap: var(--space-xs);
}

.role-btn {
    padding: var(--space-xs) var(--space-md);
    background: var(--bg-tertiary);
    border: 2px solid transparent;
    border-radius: var(--border-radius);
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
    cursor: pointer;
    transition: all 0.2s;
}

.role-btn:hover {
    border-color: var(--role-color, var(--accent));
    color: var(--text-primary);
}

.role-btn.active {
    background: var(--role-color, var(--accent));
    color: white;
    border-color: var(--role-color, var(--accent));
}

/* Empty state */
.empty-dashboard {
    grid-column: 1 / -1;
    text-align: center;
    padding: var(--space-xl);
    color: var(--text-secondary);
}

/* ============================================
   PROFILE MODAL
   ============================================ */

.user-profile-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--border-radius);
    transition: background 0.2s;
}

.user-profile-btn:hover {
    background: var(--bg-tertiary);
}

.user-profile-btn .user-name {
    color: var(--text-primary);
    font-weight: 500;
}

/* ── Notifications bell ───────────────────────────────────────────────────
   Lives in .header-right just before the user-profile-btn. Bell shows an
   unread-count badge in the top-right; clicking opens a dropdown panel
   anchored beneath the bell. */
.notifications-wrap {
    position: relative;
    display: inline-flex;
}

.notifications-bell {
    position: relative;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--border-radius);
    font-size: 18px;
    line-height: 1;
    transition: background 0.2s;
}
.notifications-bell:hover {
    background: var(--bg-tertiary);
}

.notifications-badge {
    position: absolute;
    top: 0;
    right: 0;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    background: #dc2626;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
    box-sizing: border-box;
    display: none;          /* shown via .is-visible */
    pointer-events: none;
}
.notifications-badge.is-visible { display: inline-block; }

.notifications-panel {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    width: 360px;
    max-width: 90vw;
    max-height: 70vh;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.25);
    display: none;          /* shown via .is-open */
    flex-direction: column;
    overflow: hidden;
    z-index: 1500;
}
.notifications-panel.is-open { display: flex; }

.notifications-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-color);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}
.notif-read-all {
    background: none;
    border: none;
    color: var(--accent, #2563eb);
    font-size: 12px;
    cursor: pointer;
    padding: 2px 6px;
}
.notif-read-all:hover { text-decoration: underline; }

/* Per-user push notification preferences in the profile modal.
   Two-column row: label on the left, checkbox on the right. Pinned
   with justify-content so they line up no matter how long the label is.
   The master row is the kill switch; it gets a subtle separator and
   bolder text but otherwise behaves identically to the other rows. */
.profile-notif-prefs .profile-pref-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 2px;
    margin: 0;
    cursor: pointer;
    color: var(--text-primary);
    font-size: 13px;
    text-align: left;       /* override any inherited right-align from .form-group */
}
.profile-notif-prefs .profile-pref-name {
    flex: 1 1 auto;
    min-width: 0;
}
.profile-notif-prefs .profile-pref-row input[type="checkbox"] {
    flex: 0 0 auto;
    accent-color: var(--accent, #2563eb);
    width: 16px;
    height: 16px;
    margin: 0;
    cursor: pointer;
}
.profile-notif-prefs .profile-pref-master {
    padding-bottom: 8px;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--border-color);
}
/* Per-type rows are locked visually when the master "All" is on — they
   show as checked + disabled so the user understands they're implied,
   not editable. Cursor changes to make the locked state obvious. */
.profile-notif-prefs .profile-pref-row.is-locked {
    opacity: 0.55;
    cursor: not-allowed;
}
.profile-notif-prefs .profile-pref-row.is-locked input[type="checkbox"] {
    cursor: not-allowed;
}

/* Push opt-in toggle in the notifications header. Same visual weight as
   the Mark-all-read link; turns green once subscribed. */
.notif-push-toggle {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 11px;
    cursor: pointer;
    padding: 2px 8px;
    border-radius: 12px;
    margin-right: auto;
}
.notif-push-toggle:hover:not(:disabled) {
    color: var(--text-primary);
    border-color: var(--accent, #2563eb);
}
.notif-push-toggle.is-on {
    color: #22c55e;
    border-color: #22c55e;
}
.notif-push-toggle:disabled { opacity: 0.5; cursor: default; }

/* "Install app" button next to the push toggle. Same pill, accent tone
   so the user spots it. Hidden by default — JS shows it when the
   browser offers an install prompt OR on iOS Safari. */
.notif-install-btn {
    background: none;
    border: 1px solid var(--accent, #2563eb);
    color: var(--accent, #2563eb);
    font-size: 11px;
    cursor: pointer;
    padding: 2px 8px;
    border-radius: 12px;
    margin-right: 6px;
}
.notif-install-btn:hover {
    background: color-mix(in srgb, var(--accent, #2563eb) 12%, transparent);
}

.notifications-list {
    flex: 1 1 auto;
    overflow-y: auto;
    min-height: 80px;
}
.notif-empty {
    padding: 24px 14px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
}

.notif-item {
    display: grid;
    grid-template-columns: 14px 1fr 24px;
    align-items: start;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.15s;
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--bg-tertiary); }

.notif-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-top: 6px;
    background: transparent;
}
.notif-item.is-unread .notif-dot { background: var(--accent, #2563eb); }
.notif-item.is-unread .notif-title { font-weight: 600; }

.notif-body { min-width: 0; }
.notif-title {
    font-size: 13px;
    color: var(--text-primary);
    line-height: 1.3;
}
.notif-message {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
    line-height: 1.35;
    word-wrap: break-word;
}

/* Optional thumbnail for notification types that carry one (e.g. an
   uploaded design version). Always 2:1 — same canonical aspect ratio used
   for design thumbs everywhere else in the app, so the rep can see the
   whole design at a glance from the bell dropdown. */
.notif-thumb {
    margin-top: 6px;
    width: 100%;
    aspect-ratio: 2;
    overflow: hidden;
    border-radius: 4px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
}
.notif-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
/* When the notification carries a design_version, the thumbnail click
   opens DesignChat — give it a pointer + tiny hover lift so the rep
   knows it's interactive. */
.notif-thumb.is-clickable        { cursor: pointer; transition: transform 0.12s; }
.notif-thumb.is-clickable:hover  { transform: scale(1.01); }

/* Project + order anchors below the message body. Pill-styled so they
   read as clickable distinct from the row's own click target. */
.notif-links {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}
.notif-link {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 11px;
    color: var(--text-primary);
    text-decoration: none;
    line-height: 1.5;
}
.notif-link:hover {
    background: var(--bg-secondary);
    border-color: var(--accent);
}

.notif-time {
    font-size: 11px;
    color: var(--text-muted, var(--text-secondary));
    margin-top: 4px;
}

.notif-dismiss {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    padding: 0 4px;
    border-radius: 4px;
    align-self: start;
    visibility: hidden;
}
.notif-dismiss:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
}
.notif-item:hover .notif-dismiss { visibility: visible; }

.modal-profile {
    max-width: 500px;
}

.profile-avatar-section {
    display: flex;
    align-items: flex-start;
    gap: var(--space-lg);
    margin-bottom: var(--space-lg);
}

.profile-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}

.profile-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.profile-avatar .avatar-initials {
    color: white;
    font-size: 24px;
    font-weight: 600;
}

.avatar-upload {
    flex: 1;
}

.avatar-upload label {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.avatar-upload input {
    width: 100%;
}

.profile-roles {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
}

.role-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    color: white;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Avatar upload controls */
.avatar-controls {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    align-items: flex-start;
}

.btn-upload {
    cursor: pointer;
    background: var(--bg-tertiary);
    border: 1px dashed var(--border-color);
}

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

.profile-avatar.uploading {
    opacity: 0.5;
    position: relative;
}

.profile-avatar.uploading::after {
    content: '⏳';
    position: absolute;
    font-size: 24px;
}

/* Danger button */
.btn-danger {
    background: #dc3545;
    color: white;
    border-color: #dc3545;
}

.btn-danger:hover {
    background: #c82333;
    border-color: #bd2130;
}

/* Override browser autofill styles for dark theme */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
    -webkit-box-shadow: 0 0 0 30px var(--bg-tertiary) inset !important;
    -webkit-text-fill-color: var(--text-primary) !important;
    box-shadow: 0 0 0 30px var(--bg-tertiary) inset !important;
    caret-color: var(--text-primary);
    transition: background-color 5000s ease-in-out 0s;
}

/* ============================================
   MOBILE BURGER MENU
   ============================================ */

.burger-btn {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 40px;
    height: 40px;
    padding: 8px;
    background: transparent;
    border: none;
    cursor: pointer;
    z-index: 102;
}

.burger-line {
    width: 100%;
    height: 3px;
    background: var(--text-primary);
    border-radius: 2px;
    transition: all 0.3s;
}

.burger-btn.active .burger-line:nth-child(1) {
    transform-origin: center;
    transform: translateY(8px) rotate(45deg);
}

.burger-btn.active .burger-line:nth-child(2) {
    opacity: 0;
}

.burger-btn.active .burger-line:nth-child(3) {
    transform-origin: center;
    transform: translateY(-8px) rotate(-45deg);
}

.mobile-menu {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    left: 0;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: var(--space-md);
    flex-direction: column;
    gap: var(--space-sm);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 101;
}

.mobile-menu.open {
    display: flex;
}

.mobile-menu-section {
    padding: var(--space-sm) 0;
    border-bottom: 1px solid var(--border-color);
}

.mobile-menu-label {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: var(--space-xs);
    display: block;
}

.mobile-role-switcher {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
    margin-top: var(--space-xs);
}

.mobile-menu-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-xs);
    color: var(--text-primary);
    text-decoration: none;
    background: transparent;
    border: none;
    font-size: var(--font-size-md);
    cursor: pointer;
    width: 100%;
    text-align: left;
}

.mobile-menu-item:hover {
    background: var(--bg-tertiary);
    border-radius: var(--border-radius);
}

/* ============================================
   RESPONSIVE BREAKPOINTS
   ============================================ */

@media (max-width: 768px) {
    .dashboard-header {
        padding: var(--space-sm) var(--space-md);
        position: relative;
        /* Drop space-between — with only 3 visible children (logo, header-right
           wrap, burger) it would push the bell into the middle. We pin the
           bell+burger cluster to the right via margin-left: auto on the
           header-right wrap instead. */
        justify-content: flex-start;
        gap: 0;
    }

    .header-center {
        display: none;
    }

    /* On mobile, .header-right stays visible but only the notifications bell
       shows through — theme toggle, profile button and logout link all live
       in the burger menu instead. */
    .header-right {
        gap: 0;
        margin-left: auto;   /* push the bell flush against the burger */
    }
    .header-right > *:not(.notifications-wrap) {
        display: none;
    }

    /* Anchor the dropdown to the bell's right edge, then size it so it can
       never overflow either side of the viewport. width: auto so the
       max-width actually wins over the desktop fixed width. */
    .notifications-panel {
        right: 0;
        width: auto;
        min-width: 280px;
        max-width: calc(100vw - var(--space-md) * 2);
    }

    .burger-btn {
        display: flex;
        margin-left: var(--space-sm);   /* small gap from the bell */
    }

    .widget-grid {
        padding: var(--space-sm);
        gap: var(--space-sm);
    }
}
