:root {
  --bg: #f8f9fa;
  --surface: #ffffff;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --text: #0f172a;
  --muted: #64748b;
  --sidebar-bg: #1e293b;
  --sidebar-text: #cbd5e1;
  --sidebar-active: #2563eb;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }

.hidden { display: none !important; }

/* LOGIN */
.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%); }
.login-card { background: var(--surface); border-radius: 12px; padding: 2.5rem; width: 100%; max-width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.login-logo { text-align: center; margin-bottom: 2rem; }
.login-logo h1 { font-size: 1.5rem; font-weight: 700; color: var(--primary); }
.login-logo p { color: var(--muted); margin-top: 4px; font-size: 13px; }

/* LAYOUT */
#main-app, #admin-app { display: flex; height: 100vh; overflow: hidden; }
.sidebar { width: 220px; background: var(--sidebar-bg); display: flex; flex-direction: column; flex-shrink: 0; }
.sidebar-admin { background: #1a0533; }
.sidebar-header { padding: 1.25rem 1rem; border-bottom: 1px solid rgba(255,255,255,0.1); }
.sidebar-logo { font-weight: 800; font-size: 1.1rem; color: white; margin-right: 8px; }
.sidebar-biz { font-size: 12px; color: var(--sidebar-text); display: block; margin-top: 4px; }
.sidebar-nav { flex: 1; padding: 1rem 0; list-style: none; }
.sidebar-nav li a { display: block; padding: 0.6rem 1rem; color: var(--sidebar-text); text-decoration: none; border-radius: 6px; margin: 2px 8px; font-size: 13px; transition: all 0.15s; }
.sidebar-nav li a:hover, .sidebar-nav li a.active { background: rgba(255,255,255,0.1); color: white; }
.sidebar-footer { padding: 1rem; border-top: 1px solid rgba(255,255,255,0.1); }
.content { flex: 1; overflow-y: auto; }
.page { padding: 1.5rem; }

/* PAGE HEADER */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; }
.page-title { font-size: 1.25rem; font-weight: 600; }

/* CARDS */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.card-title { font-weight: 600; font-size: 0.9rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }

/* STATS GRID */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; }
.stat-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.stat-value { font-size: 1.75rem; font-weight: 700; }
.stat-value.green { color: var(--success); }
.stat-value.blue { color: var(--primary); }
.stat-value.orange { color: var(--warning); }

/* TABLES */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; padding: 0.6rem 1rem; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; border-bottom: 1px solid var(--border); }
td { padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg); }

/* BADGES */
.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-green { background: #dcfce7; color: #166534; }
.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-orange { background: #fef3c7; color: #92400e; }
.badge-gray { background: #f1f5f9; color: var(--muted); }
.badge-red { background: #fee2e2; color: #991b1b; }

/* FORMS */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 4px; font-size: 13px; font-weight: 500; color: var(--muted); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
input, select, textarea { width: 100%; padding: 0.5rem 0.75rem; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; font-family: inherit; background: var(--surface); color: var(--text); transition: border-color 0.15s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); }
textarea { resize: vertical; min-height: 80px; }

/* BUTTONS */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 0.5rem 1rem; border-radius: 6px; font-size: 13px; font-weight: 500; cursor: pointer; border: none; transition: all 0.15s; text-decoration: none; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-ghost { background: transparent; color: var(--sidebar-text); border: 1px solid rgba(255,255,255,0.2); }
.btn-ghost:hover { background: rgba(255,255,255,0.1); }
.btn-outline { background: transparent; color: var(--primary); border: 1px solid var(--primary); }
.btn-outline:hover { background: var(--primary); color: white; }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; }
.btn-icon { padding: 0.4rem; border-radius: 6px; background: transparent; border: 1px solid var(--border); cursor: pointer; color: var(--muted); }
.btn-icon:hover { background: var(--bg); }

/* ALERTS */
.alert { padding: 0.75rem 1rem; border-radius: 6px; margin-bottom: 1rem; font-size: 13px; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.alert-info { background: #dbeafe; color: #1d4ed8; border: 1px solid #93c5fd; }

/* CONVERSATIONS */
.conv-list { display: flex; flex-direction: column; gap: 0; }
.conv-item { display: flex; align-items: center; gap: 12px; padding: 0.85rem 1rem; border-bottom: 1px solid var(--border); cursor: pointer; transition: background 0.1s; }
.conv-item:hover { background: var(--bg); }
.conv-item.active { background: #eff6ff; }
.conv-avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--primary); color: white; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 14px; flex-shrink: 0; }
.conv-info { flex: 1; min-width: 0; }
.conv-name { font-weight: 600; font-size: 13px; }
.conv-preview { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 11px; color: var(--muted); flex-shrink: 0; }

/* MESSAGE THREAD */
.message-thread { display: flex; flex-direction: column; gap: 8px; padding: 1rem; }
.msg { max-width: 70%; }
.msg-inbound { align-self: flex-start; }
.msg-outbound { align-self: flex-end; }
.msg-bubble { padding: 0.6rem 0.9rem; border-radius: 12px; font-size: 13px; line-height: 1.5; }
.msg-inbound .msg-bubble { background: var(--bg); border: 1px solid var(--border); }
.msg-outbound .msg-bubble { background: var(--primary); color: white; }
.msg-time { font-size: 11px; color: var(--muted); margin-top: 3px; padding: 0 4px; }
.msg-outbound .msg-time { text-align: right; }

/* INVOICE ITEMS */
.invoice-items-table { width: 100%; border-collapse: collapse; margin: 1rem 0; }
.invoice-items-table th, .invoice-items-table td { padding: 8px; border: 1px solid var(--border); }
.invoice-items-table th { background: var(--bg); }
.item-row-remove { cursor: pointer; color: var(--danger); padding: 4px 8px; background: none; border: none; font-size: 16px; }

/* MODAL */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal-box { background: var(--surface); border-radius: 12px; width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; margin: 1rem; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border); }
.modal-header h3 { font-size: 1rem; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 1.1rem; cursor: pointer; color: var(--muted); padding: 4px; }
#modal-body { padding: 1.5rem; }

/* SEARCH */
.search-bar { position: relative; }
.search-bar input { padding-left: 2rem; }
.search-bar::before { content: '🔍'; position: absolute; left: 8px; top: 50%; transform: translateY(-50%); font-size: 12px; pointer-events: none; }

/* TWO-COL CONVERSATION LAYOUT */
.conv-layout { display: grid; grid-template-columns: 320px 1fr; height: calc(100vh - 3rem); }
.conv-sidebar { border-right: 1px solid var(--border); overflow-y: auto; }
.conv-main { display: flex; flex-direction: column; }
.conv-thread-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.conv-thread-body { flex: 1; overflow-y: auto; }
.conv-thread-footer { padding: 1rem; border-top: 1px solid var(--border); display: flex; gap: 8px; }
.conv-thread-footer textarea { flex: 1; min-height: 40px; max-height: 120px; }

/* EMPTY STATE */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty-state-icon { font-size: 2.5rem; margin-bottom: 1rem; }
.empty-state h3 { font-size: 1rem; font-weight: 600; color: var(--text); margin-bottom: 6px; }

/* TWO-PANEL GRIDS */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }

@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .sidebar-biz, .sidebar-nav li a span { display: none; }
  .conv-layout { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
