/* ═══════════════════════════════════════════════════════════════════════════
   ServiceDesk Pro — Design System
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Tokens ─────────────────────────────────────────────────────────────── */
:root {
  --accent:        #2563eb;
  --accent-dark:   #1d4ed8;
  --accent-light:  #dbeafe;
  --success:       #16a34a;
  --warning:       #d97706;
  --danger:        #dc2626;
  --purple:        #7c3aed;

  --bg:            #f8fafc;
  --surface:       #ffffff;
  --surface-2:     #f1f5f9;
  --border:        #e2e8f0;
  --border-dark:   #cbd5e1;

  --text:          #0f172a;
  --text-2:        #475569;
  --text-3:        #94a3b8;

  --sidebar-bg:    #0f172a;
  --sidebar-text:  #cbd5e1;
  --sidebar-hover: rgba(255,255,255,.07);
  --sidebar-active:#2563eb;
  --sidebar-w:     240px;
  --topbar-h:      60px;

  --radius:        10px;
  --radius-lg:     14px;
  --shadow:        0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-lg:     0 10px 25px rgba(0,0,0,.12);

  --font:          'Inter', system-ui, sans-serif;
  --font-mono:     'JetBrains Mono', monospace;
  --transition:    150ms cubic-bezier(.4,0,.2,1);
}

[data-theme="dark"] {
  --bg:        #0d1117;
  --surface:   #161b22;
  --surface-2: #21262d;
  --border:    #30363d;
  --border-dark:#484f58;
  --text:      #e6edf3;
  --text-2:    #8b949e;
  --text-3:    #484f58;
  --sidebar-bg:#010409;
}

/* ── Reset & Base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; scroll-behavior: smooth; }
body { font-family: var(--font); background: var(--bg); color: var(--text);
       line-height: 1.6; min-height: 100vh; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }

/* ── Layout ──────────────────────────────────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform var(--transition);
}

.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-name { font-size: .95rem; font-weight: 700; color: #fff; letter-spacing: -.01em; }
.sidebar-toggle { background: none; border: none; color: var(--sidebar-text);
                  cursor: pointer; font-size: 1rem; display: none; }

.nav-menu { flex: 1; padding: 12px 8px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 8px;
  color: var(--sidebar-text); font-size: .9rem; font-weight: 500;
  transition: background var(--transition), color var(--transition);
  margin-bottom: 2px;
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--sidebar-active); color: #fff; }
.nav-icon { font-size: 1rem; width: 20px; text-align: center; }

.sidebar-footer { padding: 12px 8px; border-top: 1px solid rgba(255,255,255,.06); }
.user-card { display: flex; align-items: center; gap: 10px; padding: 8px; }
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .85rem; flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name { display: block; font-size: .82rem; font-weight: 600; color: #fff;
             white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { display: block; font-size: .72rem; color: var(--text-3); text-transform: capitalize; }
.logout-btn { color: var(--sidebar-text); font-size: 1rem;
              opacity: .6; transition: opacity var(--transition); }
.logout-btn:hover { opacity: 1; text-decoration: none; }

.main-wrap {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  position: sticky; top: 0; z-index: 50;
}
.menu-btn { background: none; border: none; cursor: pointer; font-size: 1.2rem;
            color: var(--text-2); display: none; }
.topbar-right { display: flex; align-items: center; gap: 12px; }

.active-timer {
  display: flex; align-items: center; gap: 8px;
  background: #fef3c7; border: 1px solid #fde68a;
  padding: 5px 12px; border-radius: 20px; font-size: .82rem;
}
.timer-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger);
             animation: pulse 1.5s infinite; }
@keyframes pulse { 0%,100%{opacity:1;transform:scale(1)} 50%{opacity:.5;transform:scale(1.3)} }
.timer-label { font-family: var(--font-mono); font-weight: 600; color: var(--text); }
.btn-stop-timer { background: var(--danger); color: #fff; border: none; border-radius: 12px;
                  padding: 2px 10px; font-size: .76rem; cursor: pointer; }

.theme-toggle { background: none; border: 1px solid var(--border); border-radius: 8px;
                padding: 5px 9px; cursor: pointer; color: var(--text-2); font-size: 1rem; }

.content { padding: 28px 28px; flex: 1; }

/* ── Auth layout ─────────────────────────────────────────────────────────── */
.auth-layout { min-height: 100vh; display: flex; align-items: center; justify-content: center;
               padding: 24px; background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 50%, #dbeafe 100%); }
[data-theme="dark"] .auth-layout { background: linear-gradient(135deg, #0d1117 0%, #0f172a 100%); }
.auth-card { background: var(--surface); border-radius: 20px; padding: 40px;
             box-shadow: var(--shadow-lg); width: 100%; max-width: 400px; }
.auth-brand { text-align: center; margin-bottom: 32px; }
.auth-brand h1 { font-size: 1.4rem; font-weight: 800; margin: 12px 0 4px; letter-spacing: -.02em; }
.auth-brand p { color: var(--text-2); font-size: .88rem; }
.auth-brand svg { margin: 0 auto; }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border);
        border-radius: var(--radius-lg); box-shadow: var(--shadow); overflow: hidden; }
.card-header { display: flex; align-items: center; justify-content: space-between;
               padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-title { font-size: 1rem; font-weight: 600; }
.card-body { padding: 20px; }
.card-body.p-0 { padding: 0; }
.card-body.p-4 { padding: 1rem; }
.mt-4 { margin-top: 1.5rem; }
.mb-4 { margin-bottom: 1.5rem; }

/* ── Page header ─────────────────────────────────────────────────────────── */
.page-header { display: flex; align-items: flex-start; justify-content: space-between;
               margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }
.page-title { font-size: 1.5rem; font-weight: 800; letter-spacing: -.02em; }
.page-subtitle { color: var(--text-2); font-size: .88rem; margin-top: 2px; }
.page-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.back-link { color: var(--text-2); font-size: .85rem; display: block; margin-bottom: 4px; }
.back-link:hover { color: var(--accent); }

/* ── Stats ───────────────────────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(var(--grid-cols, 4), 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
             padding: 20px; display: flex; align-items: center; gap: 16px; box-shadow: var(--shadow); }
.stat-icon { width: 48px; height: 48px; border-radius: 12px; display: flex;
             align-items: center; justify-content: center; font-size: 1.4rem; flex-shrink: 0; }
.stat-icon--blue   { background: #dbeafe; }
.stat-icon--green  { background: #dcfce7; }
.stat-icon--yellow { background: #fef9c3; }
.stat-icon--purple { background: #f3e8ff; }
.stat-value { font-size: 1.4rem; font-weight: 800; letter-spacing: -.02em; }
.stat-label { font-size: .78rem; color: var(--text-2); margin-top: 2px; }

/* ── Dashboard grid ──────────────────────────────────────────────────────── */
.dashboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 8px;
  font-size: .875rem; font-weight: 500; font-family: var(--font);
  cursor: pointer; border: none; transition: all var(--transition);
  text-decoration: none !important; white-space: nowrap;
}
.btn-primary  { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); color: #fff; }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-ghost    { background: transparent; color: var(--text-2); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-danger-ghost { background: transparent; color: var(--danger); border: 1px solid transparent;
                    padding: 4px 8px; font-size: .8rem; }
.btn-danger-ghost:hover { background: #fee2e2; }
.btn-sm  { padding: 5px 12px; font-size: .8rem; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 5px; margin-bottom: 16px; }
.form-group label { font-size: .82rem; font-weight: 600; color: var(--text-2); }
.form-control {
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: .875rem; font-family: var(--font); background: var(--surface);
  color: var(--text); transition: border-color var(--transition), box-shadow var(--transition);
  width: 100%;
}
.form-control:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }
input[type="color"].form-control { padding: 3px 6px; height: 42px; cursor: pointer; }
.form-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.form-group--1 { grid-column: span 1; }
.form-group--2 { grid-column: span 2; }
.form-group--3 { grid-column: span 3; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; padding-top: 8px; border-top: 1px solid var(--border); margin-top: 8px; }
.input-group { position: relative; display: flex; }
.input-group .form-control { border-radius: 8px 0 0 8px; flex: 1; }
.input-addon { border: 1px solid var(--border); border-left: none; background: var(--surface-2);
               border-radius: 0 8px 8px 0; padding: 0 12px; cursor: pointer; color: var(--text-2); }
.checkbox-label { display: flex; align-items: center; gap: 8px; font-size: .88rem;
                  cursor: pointer; font-weight: 400; }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.data-table th { padding: 10px 16px; text-align: left; font-size: .75rem; font-weight: 600;
                 color: var(--text-2); text-transform: uppercase; letter-spacing: .05em;
                 background: var(--surface-2); border-bottom: 1px solid var(--border); }
.data-table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--surface-2); }
.actions-cell { white-space: nowrap; }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; padding: 3px 9px;
         border-radius: 20px; font-size: .72rem; font-weight: 600; text-transform: capitalize; }
.badge-scheduled  { background: var(--accent-light); color: var(--accent); }
.badge-in_progress { background: #fef3c7; color: #b45309; }
.badge-completed   { background: #dcfce7; color: var(--success); }
.badge-cancelled   { background: #fee2e2; color: var(--danger); }
.badge-status-draft    { background: var(--surface-2); color: var(--text-2); }
.badge-status-sent     { background: #dbeafe; color: var(--accent); }
.badge-status-approved { background: #dcfce7; color: var(--success); }
.badge-priority-low      { background: #dbeafe; color: var(--accent); }
.badge-priority-medium   { background: #fef9c3; color: #b45309; }
.badge-priority-high     { background: #fed7aa; color: #c2410c; }
.badge-priority-critical { background: #fee2e2; color: var(--danger); }

/* ── Tasks ───────────────────────────────────────────────────────────────── */
.task-group { margin-bottom: 20px; }
.task-group-title { font-size: .78rem; font-weight: 700; text-transform: uppercase;
                    letter-spacing: .08em; color: var(--text-2); margin-bottom: 8px; padding: 0 2px; }
.task-item { display: flex; align-items: center; gap: 12px; padding: 11px 14px;
             border-radius: 8px; transition: background var(--transition); }
.task-item:hover { background: var(--surface-2); }
.task-checkbox { width: 18px; height: 18px; border-radius: 4px; cursor: pointer;
                 accent-color: var(--accent); flex-shrink: 0; }
.task-info { flex: 1; min-width: 0; }
.task-title { font-size: .875rem; font-weight: 500; }
.task-meta  { font-size: .76rem; color: var(--text-2); margin-top: 1px; }
.task-done .task-title { text-decoration: line-through; color: var(--text-3); }
.task-overdue { border-left: 3px solid var(--danger); padding-left: 11px; }
.task-actions { display: flex; gap: 4px; opacity: 0; transition: opacity var(--transition); }
.task-item:hover .task-actions { opacity: 1; }

/* ── Schedule items ──────────────────────────────────────────────────────── */
.schedule-item { display: flex; align-items: center; gap: 12px; padding: 10px;
                 border-radius: 8px; transition: background var(--transition); }
.schedule-item:hover { background: var(--surface-2); }
.schedule-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.schedule-info { flex: 1; min-width: 0; }
.schedule-title { font-size: .875rem; font-weight: 500; }
.schedule-meta  { font-size: .76rem; color: var(--text-2); }
.schedule-actions { display: flex; gap: 4px; opacity: 0; transition: opacity var(--transition); }
.schedule-item:hover .schedule-actions { opacity: 1; }

/* ── Calendar ────────────────────────────────────────────────────────────── */
.month-label { font-weight: 700; min-width: 160px; text-align: center; }
.cal-header { display: grid; grid-template-columns: repeat(7,1fr);
              background: var(--surface-2); border-bottom: 1px solid var(--border); }
.cal-header > div { padding: 10px; text-align: center; font-size: .78rem;
                    font-weight: 600; color: var(--text-2); text-transform: uppercase; }
.cal-body { display: grid; grid-template-columns: repeat(7,1fr); }
.cal-day { min-height: 90px; padding: 6px; border-right: 1px solid var(--border);
           border-bottom: 1px solid var(--border); cursor: pointer;
           transition: background var(--transition); }
.cal-day:hover { background: var(--surface-2); }
.cal-day--empty { background: var(--bg); cursor: default; }
.cal-day--today .cal-day-num { background: var(--accent); color: #fff; border-radius: 50%;
                                width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; }
.cal-day-num { font-size: .82rem; font-weight: 600; margin-bottom: 4px;
               width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; }
.cal-events { display: flex; flex-direction: column; gap: 2px; }
.cal-event { font-size: .68rem; padding: 2px 5px; border-radius: 4px;
             background: var(--accent-light); border-left: 3px solid var(--accent);
             white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.cal-event:hover { opacity: .8; }
.cal-event-more { font-size: .68rem; color: var(--text-3); padding: 2px 5px; }

/* ── Alerts ──────────────────────────────────────────────────────────────── */
.alert { padding: 10px 14px; border-radius: 8px; font-size: .875rem; }
.alert-danger { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4);
                 z-index: 200; opacity: 0; pointer-events: none;
                 transition: opacity var(--transition); }
.modal-overlay.active { opacity: 1; pointer-events: all; }
.modal { position: fixed; top: 50%; left: 50%; transform: translate(-50%,-50%) scale(.95);
         background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
         width: 90%; max-width: 520px; z-index: 201; max-height: 90vh; overflow-y: auto;
         opacity: 0; pointer-events: none; transition: all var(--transition); }
.modal.modal-lg  { max-width: 720px; }
.modal.modal--wide { max-width: 680px; }
.modal.active { opacity: 1; pointer-events: all; transform: translate(-50%,-50%) scale(1); }
.modal-header { display: flex; align-items: center; justify-content: space-between;
                padding: 18px 20px; border-bottom: 1px solid var(--border); position: sticky; top: 0;
                background: var(--surface); z-index: 1; }
.modal-title { font-size: 1rem; font-weight: 700; }
.modal-close { background: none; border: none; cursor: pointer; font-size: 1rem;
               color: var(--text-2); padding: 4px 8px; border-radius: 6px; }
.modal-close:hover { background: var(--surface-2); }
.modal-body { padding: 20px; }

/* ── Toast ───────────────────────────────────────────────────────────────── */
#toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 300;
                   display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 12px 18px; border-radius: 10px; font-size: .875rem; font-weight: 500;
         box-shadow: var(--shadow-lg); animation: slideUp .2s ease; display: flex; align-items: center; gap: 8px; }
.toast-success { background: #166534; color: #fff; }
.toast-error   { background: #991b1b; color: #fff; }
.toast-info    { background: #1e40af; color: #fff; }
@keyframes slideUp { from{transform:translateY(20px);opacity:0} to{transform:translateY(0);opacity:1} }

/* ── Loading ─────────────────────────────────────────────────────────────── */
.loading-spinner { display: flex; align-items: center; justify-content: center; padding: 40px; }
.loading-spinner::after { content: ''; width: 32px; height: 32px; border: 3px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Misc ────────────────────────────────────────────────────────────────── */
.empty-state { text-align: center; color: var(--text-3); padding: 32px; font-size: .9rem; }
.link { color: var(--accent); font-weight: 500; }
.link:hover { text-decoration: underline; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 12px;
              padding: 14px; border-top: 1px solid var(--border); font-size: .85rem; color: var(--text-2); }
.date-badge { font-size: .82rem; color: var(--text-2); background: var(--surface-2);
              padding: 5px 12px; border-radius: 20px; border: 1px solid var(--border); }
.toggle-label { display: flex; align-items: center; gap: 8px; font-size: .85rem;
                cursor: pointer; color: var(--text-2); }

/* ── Print ───────────────────────────────────────────────────────────────── */
@media print {
  .sidebar, .topbar, .page-actions, .btn, .modal { display: none !important; }
  .main-wrap { margin: 0; }
  .content { padding: 0; }
  .card { box-shadow: none; border: 1px solid #ddd; }
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(2,1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  :root { --sidebar-w: 260px; }
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .sidebar-toggle, .menu-btn { display: flex; }
  .main-wrap { margin-left: 0; }
  .content { padding: 16px; }
  .topbar { padding: 0 16px; }
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .form-row { grid-template-columns: 1fr; }
  .form-group--1, .form-group--2, .form-group--3 { grid-column: span 1; }
  .data-table { font-size: .8rem; }
  .data-table th, .data-table td { padding: 8px 10px; }
  .cal-day { min-height: 60px; }
  .cal-event { display: none; }
  .page-header { flex-direction: column; }
  .modal { width: 95%; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .topbar-right .btn-primary { display: none; }
}
