/* ===== CSS VARIABLES ===== */
:root {
  --bg:              #f9fafb;
  --bg-nav:          #ffffff;
  --bg-card:         #ffffff;
  --bg-table-header: #f9fafb;
  --bg-hover:        #f0f4ff;
  --bg-input:        #ffffff;
  --bg-auth:         linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
  --text:            #1a1a2e;
  --text-muted:      #888888;
  --text-subtle:     #555555;
  --border:          #eeeeee;
  --border-input:    #e2e8f0;
  --border-light:    #f0f0f0;
  --shadow-sm:       rgba(0,0,0,0.05);
  --shadow-md:       rgba(0,0,0,0.15);
  --comment-internal-bg: #fffbeb;
  --comment-border-bottom: #f0f0f0;
}

html.dark {
  --bg:              #0f172a;
  --bg-nav:          #1e293b;
  --bg-card:         #1e293b;
  --bg-table-header: #162032;
  --bg-hover:        #1e3a5f;
  --bg-input:        #0f172a;
  --bg-auth:         linear-gradient(135deg, #0a1628 0%, #1e3a5f 100%);
  --text:            #e2e8f0;
  --text-muted:      #94a3b8;
  --text-subtle:     #94a3b8;
  --border:          #334155;
  --border-input:    #334155;
  --border-light:    #253347;
  --shadow-sm:       rgba(0,0,0,0.25);
  --shadow-md:       rgba(0,0,0,0.4);
  --comment-internal-bg: #2a2010;
  --comment-border-bottom: #253347;
}

/* ===== BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; color: var(--text); line-height: 1.6; background: var(--bg); transition: background 0.2s, color 0.2s; }

/* ===== NAV ===== */
nav { display: flex; justify-content: space-between; align-items: center; padding: 1rem 2rem; border-bottom: 1px solid var(--border); background: var(--bg-nav); }
.logo { font-size: 1.25rem; font-weight: 700; text-decoration: none; color: var(--text); }
.nav-links { display: flex; gap: 1rem; align-items: center; }
.nav-links a { text-decoration: none; color: var(--text-subtle); font-size: 0.9rem; }
.nav-links a:hover { color: #2563eb; }
.nav-user { color: var(--text-muted); font-size: 0.85rem; }

/* Theme toggle */
.theme-toggle { background: none; border: 1px solid var(--border-input); border-radius: 6px; padding: 0.2rem 0.55rem; cursor: pointer; font-size: 1rem; color: var(--text-subtle); line-height: 1; transition: background 0.15s; }
.theme-toggle:hover { background: var(--bg-hover); }

/* ===== LAYOUT ===== */
main { padding: 2rem; max-width: 1200px; margin: 0 auto; }
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
.page-header h1 { font-size: 1.5rem; }

/* ===== BUTTONS ===== */
.btn { display: inline-block; padding: 0.5rem 1.25rem; border-radius: 6px; text-decoration: none; font-weight: 500; border: 1px solid var(--border); color: var(--text); cursor: pointer; font-size: 0.9rem; background: var(--bg-card); }
.btn-primary { background: #2563eb; color: #fff; border-color: #2563eb; }
.btn-primary:hover { background: #1d4ed8; }
.btn-danger { background: #ef4444; color: #fff; border-color: #ef4444; }
.btn-sm { padding: 0.25rem 0.75rem; font-size: 0.8rem; }
.btn-full { width: 100%; text-align: center; }
.btn-active { background: #2563eb; color: #fff; border-color: #2563eb; }

/* ===== AUTH ===== */
.auth-page { display: flex; justify-content: center; align-items: center; min-height: 100vh; background: var(--bg-auth); }
.auth-card { background: var(--bg-card); padding: 2.5rem; border-radius: 16px; box-shadow: 0 25px 50px var(--shadow-md); width: 100%; max-width: 400px; }
.auth-logo { text-align: center; font-size: 1.5rem; font-weight: 800; color: var(--text); letter-spacing: -0.03em; margin-bottom: 0.25rem; }
.auth-subtitle { text-align: center; color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1.75rem; }
.auth-card h1 { margin-bottom: 1.5rem; text-align: center; }
.auth-link { text-align: center; margin-top: 1rem; color: var(--text-muted); font-size: 0.9rem; }
.auth-link a { color: #2563eb; text-decoration: none; }
.auth-link a:hover { text-decoration: underline; }

/* ===== FORMS ===== */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.25rem; font-weight: 500; font-size: 0.9rem; }
.form-group input, .form-group select, .form-group textarea { width: 100%; padding: 0.625rem 0.75rem; border: 1px solid var(--border-input); border-radius: 8px; font-size: 0.95rem; font-family: inherit; outline: none; transition: border-color 0.15s, box-shadow 0.15s; background: var(--bg-input); color: var(--text); }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,0.15); }
.form-group input::placeholder { color: var(--text-muted); }
.form-group textarea { resize: vertical; }
.form-card { background: var(--bg-card); padding: 1.5rem; border-radius: 8px; max-width: 600px; box-shadow: 0 1px 3px var(--shadow-sm); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1rem; }
.inline-form { display: flex; gap: 0.5rem; margin-top: 1rem; align-items: center; }
.inline-form input { padding: 0.4rem 0.75rem; border: 1px solid var(--border); border-radius: 4px; background: var(--bg-input); color: var(--text); }

/* ===== STATS ===== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.stat-card { background: var(--bg-card); padding: 1.25rem; border-radius: 8px; text-align: center; box-shadow: 0 1px 3px var(--shadow-sm); }
.stat-number { font-size: 2rem; font-weight: 700; }
.stat-label { color: var(--text-muted); font-size: 0.85rem; }
.stat-warning .stat-number { color: #f59e0b; }
.stat-success .stat-number { color: #10b981; }

/* ===== BADGES ===== */
.badge { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 4px; font-size: 0.75rem; font-weight: 500; background: #e5e7eb; color: #374151; }
.badge-lg { font-size: 0.9rem; padding: 0.25rem 0.75rem; }
.badge-new { background: #dbeafe; color: #1e40af; }
.badge-assigned { background: #fef3c7; color: #92400e; }
.badge-in_progress { background: #e0e7ff; color: #3730a3; }
.badge-in_review { background: #ede9fe; color: #5b21b6; }
.badge-waiting_client { background: #fef3c7; color: #92400e; }
.badge-resolved { background: #d1fae5; color: #065f46; }
.badge-closed { background: #f3f4f6; color: #6b7280; }
.badge-reopened { background: #fee2e2; color: #991b1b; }
.badge-priority-low { background: #e5e7eb; color: #374151; }
.badge-priority-medium { background: #dbeafe; color: #1e40af; }
.badge-priority-high { background: #fef3c7; color: #92400e; }
.badge-priority-critical { background: #fee2e2; color: #991b1b; }
.badge-internal { background: #fef3c7; color: #92400e; }
.badge-role { background: #e0e7ff; color: #3730a3; }
.badge-role-user { background: #e5e7eb; color: #374151; }
.badge-role-agent { background: #dbeafe; color: #1e40af; }
.badge-role-org_admin { background: #e0e7ff; color: #3730a3; }
.badge-role-superadmin { background: #fce7f3; color: #9d174d; }
.badge-active { background: #d1fae5; color: #065f46; }
.badge-inactive { background: #fee2e2; color: #991b1b; }

/* Role filter buttons */
.filter-badge { display: inline-block; padding: 0.25rem 0.75rem; border-radius: 4px; font-size: 0.8rem; font-weight: 500; text-decoration: none; opacity: 0.65; transition: opacity 0.15s; }
.filter-badge:hover, .filter-selected { opacity: 1; }
.filter-user { background: #e5e7eb; color: #374151; }
.filter-agent { background: #dbeafe; color: #1e40af; }
.filter-org_admin { background: #e0e7ff; color: #3730a3; }
.filter-deleted { background: #fee2e2; color: #991b1b; }

/* ===== TICKETS ===== */
.ticket-list { display: flex; flex-direction: column; gap: 0.25rem; }
.ticket-row { display: flex; align-items: center; gap: 1rem; padding: 0.75rem 1rem; background: var(--bg-card); border-radius: 6px; text-decoration: none; color: var(--text); transition: background 0.15s; }
.ticket-row:hover { background: var(--bg-hover); }
.ticket-number { font-weight: 600; color: #2563eb; min-width: 50px; }
.ticket-title { flex: 1; }
.ticket-date { color: var(--text-muted); font-size: 0.85rem; }
.filters { display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; }

/* Ticket detail */
.ticket-detail-grid { display: grid; grid-template-columns: 1fr 300px; gap: 1.5rem; }
@media (max-width: 768px) { .ticket-detail-grid { grid-template-columns: 1fr; } }
.ticket-description p { white-space: pre-wrap; }
.ticket-meta { margin-top: 1rem; color: var(--text-muted); font-size: 0.85rem; display: flex; gap: 1rem; }
.detail-row { display: flex; justify-content: space-between; padding: 0.25rem 0; font-size: 0.9rem; }
.sidebar-form { margin-top: 0.5rem; display: flex; gap: 0.5rem; }
.sidebar-form select { flex: 1; padding: 0.3rem; border: 1px solid var(--border); border-radius: 4px; background: var(--bg-input); color: var(--text); }

/* ===== COMMENTS ===== */
.comment { padding: 0.75rem; border-bottom: 1px solid var(--comment-border-bottom); }
.comment-internal { background: var(--comment-internal-bg); border-left: 3px solid #f59e0b; }
.comment-header { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 0.25rem; font-size: 0.85rem; }
.comment-body { white-space: pre-wrap; }
.comment-form { margin-top: 1rem; }
.comment-form textarea { width: 100%; padding: 0.5rem; border: 1px solid var(--border); border-radius: 4px; font-family: inherit; margin-bottom: 0.5rem; background: var(--bg-input); color: var(--text); }
.checkbox-label { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; margin-bottom: 0.5rem; }

/* ===== CARDS ===== */
.card { background: var(--bg-card); padding: 1.25rem; border-radius: 8px; box-shadow: 0 1px 3px var(--shadow-sm); margin-bottom: 1rem; }
.card h2, .card h3 { margin-bottom: 0.75rem; }

/* ===== TABLES ===== */
.data-table { width: 100%; border-collapse: collapse; background: var(--bg-card); border-radius: 8px; overflow: hidden; }
.data-table th { text-align: left; padding: 0.75rem 1rem; background: var(--bg-table-header); font-weight: 600; font-size: 0.85rem; color: var(--text-subtle); }
.data-table td { padding: 0.75rem 1rem; border-top: 1px solid var(--border-light); }

/* ===== ALERTS ===== */
.alert { padding: 1rem; border-radius: 6px; margin-bottom: 1rem; }
.alert-error { background: #fee2e2; color: #991b1b; }
.alert-success { background: #d1fae5; color: #065f46; }
.api-key-display { display: block; margin-top: 0.5rem; padding: 0.5rem; background: var(--bg-input); border: 1px solid var(--border); border-radius: 4px; word-break: break-all; }

/* ===== MISC ===== */
.empty-state { color: var(--text-muted); text-align: center; padding: 2rem; }
.text-muted { color: var(--text-muted); }
.text-success { color: #10b981; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 1rem; margin-top: 1.5rem; }
.attachment-row { display: flex; justify-content: space-between; padding: 0.25rem 0; font-size: 0.9rem; }
