/* TPC Backoffice — Radix-inspired design system */

/* --- Tokens --- */
:root {
  /* Gray (lighter, less cold) */
  --gray-1: #fefefe; --gray-2: #fafafa; --gray-3: #f5f5f5; --gray-4: #ebebeb;
  --gray-5: #e0e0e0; --gray-6: #d4d4d4; --gray-7: #c0c0c0; --gray-8: #a3a3a3;
  --gray-9: #7a7a7a; --gray-10: #6b6b6b; --gray-11: #525252; --gray-12: #1a1a1a;
  --gray-a3: rgba(0,0,0,0.03); --gray-a4: rgba(0,0,0,0.05); --gray-a5: rgba(0,0,0,0.07);
  /* Accent (Vibrant blue) */
  --accent-1: #fbfdff; --accent-2: #f0f7ff; --accent-3: #e0efff; --accent-4: #cce3ff;
  --accent-5: #b0d4ff; --accent-6: #8cbffa; --accent-7: #64a8f4; --accent-8: #3d8de5;
  --accent-9: #2870bd; --accent-10: #1d5fa8; --accent-11: #1a6dd4; --accent-12: #0c334d;
  --accent-contrast: #fff;
  /* Lime accent (brand) */
  /* Semantic — vivid */
  --red-9: #ef4444; --red-11: #dc2626; --red-3: #fef2f2; --red-a3: rgba(239,68,68,0.06);
  --green-9: #22c55e; --green-11: #16a34a; --green-3: #f0fdf4;
  --amber-9: #f59e0b; --amber-11: #d97706; --amber-3: #fffbeb;
  --blue-9: #3b82f6; --blue-11: #2563eb;
  --purple-9: #8b5cf6; --purple-11: #7c3aed;
  /* Radius */
  --radius-1: 3px; --radius-2: 4px; --radius-3: 6px; --radius-4: 8px; --radius-5: 12px; --radius-6: 16px;
  /* Shadows */
  --shadow-1: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-2: 0 2px 4px rgba(0,0,0,0.05), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-3: 0 2px 8px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  /* Font */
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  --font-mono: 'Menlo', 'Consolas', monospace;
  /* Type scale */
  --fs-1: 12px; --fs-2: 14px; --fs-3: 16px; --fs-4: 18px; --fs-5: 20px; --fs-6: 24px;
  --lh-1: 16px; --lh-2: 20px; --lh-3: 24px; --lh-4: 26px; --lh-5: 28px; --lh-6: 30px;
}

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

body {
  font-family: var(--font-sans);
  font-size: var(--fs-2);
  line-height: var(--lh-2);
  color: var(--gray-12);
  background: var(--gray-1);
  -webkit-font-smoothing: antialiased;
}

/* --- Layout --- */
.app-shell { height: 100vh; display: flex; flex-direction: column; }
.app-content { flex: 1; overflow: auto; }

/* --- Top Bar --- */
.topbar {
  height: 48px;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
  color: #fff;
}

.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-brand { display: flex; align-items: center; gap: 8px; cursor: pointer; text-decoration: none; color: #fff; }
.topbar-brand span { font-weight: 600; font-size: var(--fs-2); letter-spacing: -0.01em; }
.topbar-breadcrumb { color: rgba(255,255,255,0.2); font-size: 14px; }
.topbar-module-name { color: rgba(255,255,255,0.7); font-size: 13px; font-weight: 500; }
.topbar-module-badge { font-size: 11px; font-weight: 500; padding: 2px 8px; border-radius: var(--radius-2); background: rgba(255,255,255,0.08); color: rgba(255,255,255,0.4); }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-divider { width: 1px; height: 16px; background: rgba(255,255,255,0.1); }

.topbar-timer { display: flex; align-items: center; gap: 4px; font-size: 11px; font-family: var(--font-mono); color: rgba(255,255,255,0.2); }
.topbar-timer.warning { color: var(--amber-9); }

.topbar-user { display: flex; align-items: center; gap: 8px; }
.topbar-avatar { width: 26px; height: 26px; border-radius: var(--radius-3); background: #fff; color: #000; display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 700; }
.topbar-user-info { line-height: 1.2; }
.topbar-user-name { font-size: 12px; font-weight: 500; }
.topbar-user-role { font-size: 10px; color: rgba(255,255,255,0.35); }

.topbar-btn { background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1); border-radius: var(--radius-2); color: rgba(255,255,255,0.6); padding: 4px 12px; font-size: 12px; cursor: pointer; display: flex; align-items: center; gap: 4px; font-family: inherit; transition: all 0.15s; }
.topbar-btn:hover { background: rgba(255,255,255,0.1); color: rgba(255,255,255,0.9); }
.topbar-btn-logout { background: none; border: 1px solid rgba(255,255,255,0.08); color: rgba(255,255,255,0.35); }

/* --- Forms --- */
.form-group { margin-bottom: 16px; }
.form-label { font-size: var(--fs-1); color: var(--gray-11); font-weight: 500; display: block; margin-bottom: 6px; }

.form-input, .form-select {
  width: 100%; padding: 8px 12px; font-size: var(--fs-2); line-height: var(--lh-2);
  border: 1px solid var(--gray-7); border-radius: var(--radius-2);
  outline: none; color: var(--gray-12); font-family: inherit; background: var(--gray-1);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-input:focus, .form-select:focus { border-color: var(--accent-8); box-shadow: 0 0 0 1px var(--accent-8); }
.form-input::placeholder { color: var(--gray-8); }

/* --- Buttons --- */
.btn {
  padding: 8px 16px; font-size: 13px; font-weight: 500;
  border-radius: var(--radius-2); cursor: pointer; border: none;
  font-family: inherit; display: inline-flex; align-items: center; gap: 6px;
  transition: all 0.15s; line-height: var(--lh-1);
}
.btn-primary { background: var(--accent-9); color: var(--accent-contrast); }
.btn-primary:hover { background: var(--accent-10); }
.btn-secondary { background: var(--gray-1); color: var(--gray-12); border: 1px solid var(--gray-7); }
.btn-secondary:hover { background: var(--gray-2); border-color: var(--gray-8); }
.btn-danger { background: var(--red-3); color: var(--red-11); border: 1px solid rgba(229,72,77,0.2); }
.btn-sm { padding: 4px 12px; font-size: 12px; }

/* --- Cards --- */
.card { background: var(--gray-1); border: 1px solid var(--gray-6); border-radius: var(--radius-4); overflow: hidden; }

/* --- Tables --- */
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead tr { background: var(--gray-2); }
th { padding: 8px 12px; text-align: left; font-weight: 500; color: var(--gray-11); font-size: var(--fs-1); border-bottom: 1px solid var(--gray-6); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--gray-4); color: var(--gray-12); }
tbody tr:hover { background: var(--gray-2); }

/* --- Badges --- */
.badge { font-size: 11px; font-weight: 500; padding: 2px 8px; border-radius: var(--radius-6); display: inline-block; }
.badge-green { background: #dcfce7; color: #15803d; }
.badge-yellow { background: #fef3c7; color: #b45309; }
.badge-red { background: #fee2e2; color: #dc2626; }
.badge-gray { background: var(--gray-3); color: var(--gray-11); }
.badge-blue { background: #dbeafe; color: #2563eb; }
.badge-purple { background: #ede9fe; color: #7c3aed; }

/* --- Tabs --- */
.tabs { display: flex; border-bottom: 1px solid var(--gray-6); padding: 0 4px; }
.tab { padding: 10px 16px; font-size: 13px; cursor: pointer; color: var(--gray-9); background: none; border: none; border-bottom: 2px solid transparent; font-family: inherit; font-weight: 500; transition: color 0.15s; }
.tab:hover { color: var(--gray-12); }
.tab.active { color: var(--accent-11); border-bottom-color: var(--accent-9); }

/* --- Toolbar --- */
.toolbar { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--gray-4); gap: 8px; }
.toolbar-left { display: flex; gap: 8px; align-items: center; }
.toolbar-right { display: flex; gap: 8px; align-items: center; }
.search-input { width: 260px; padding: 6px 12px; font-size: 13px; border: 1px solid var(--gray-7); border-radius: var(--radius-2); outline: none; color: var(--gray-12); font-family: inherit; background: var(--gray-1); }
.search-input:focus { border-color: var(--accent-8); box-shadow: 0 0 0 1px var(--accent-8); }

/* --- Stat Cards --- */
.stat-grid { display: grid; gap: 12px; margin-bottom: 24px; }
.stat-grid-3 { grid-template-columns: repeat(3, 1fr); }
.stat-grid-4 { grid-template-columns: repeat(4, 1fr); }
.stat-card { background: var(--gray-1); border: 1px solid var(--gray-6); border-radius: var(--radius-4); padding: 16px 20px; }
.stat-label { font-size: 11px; color: var(--gray-9); margin-bottom: 4px; font-weight: 500; }
.stat-value { font-size: 26px; font-weight: 600; color: var(--accent-12); letter-spacing: -0.02em; line-height: 1.1; }
.stat-value.alert { color: var(--red-9); }
.stat-sub { font-size: 11px; color: var(--gray-9); margin-top: 4px; }

/* --- Portal Grid --- */
.portal-wrapper { padding: 40px; }
.portal-content { max-width: 840px; margin: 0 auto; }
.portal-welcome h1 { margin: 0 0 4px; font-size: var(--fs-6); font-weight: 600; color: var(--gray-12); letter-spacing: -0.02em; }
.portal-welcome p { margin: 0; font-size: var(--fs-2); color: var(--gray-9); }

.category-section { margin-bottom: 32px; }
.category-header { display: flex; align-items: center; gap: 6px; margin-bottom: 12px; }
.category-header svg { color: var(--gray-8); }
.category-header span { font-size: 11px; font-weight: 600; color: var(--gray-9); text-transform: uppercase; letter-spacing: 0.05em; }

.module-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.module-card { background: var(--gray-1); border: 1px solid var(--gray-6); border-radius: var(--radius-4); padding: 16px 20px; cursor: pointer; transition: all 0.15s; }
.module-card:hover { border-color: var(--accent-8); box-shadow: 0 2px 8px rgba(40,112,189,0.12); }
.module-card.planned { opacity: 0.5; cursor: default; }
.module-card.planned:hover { border-color: var(--gray-6); box-shadow: none; }
.module-card-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 10px; }
.module-icon { width: 36px; height: 36px; border-radius: var(--radius-3); display: flex; align-items: center; justify-content: center; }
.module-icon.live { background: #000; color: #fff; }
.module-icon.dev, .module-icon.planned { background: var(--gray-3); color: var(--gray-9); }
.module-name { font-size: var(--fs-2); font-weight: 600; color: var(--gray-12); margin-bottom: 2px; }
.module-desc { font-size: var(--fs-1); color: var(--gray-9); line-height: 1.5; }
.module-url { margin-top: 8px; font-size: 11px; color: var(--gray-8); font-family: var(--font-mono); }

/* --- Monospace --- */
.mono { font-family: var(--font-mono); font-size: 12px; }

/* --- Utility --- */
.text-link { color: var(--accent-11); cursor: pointer; font-size: 12px; font-weight: 500; background: none; border: none; font-family: inherit; }
.text-link:hover { text-decoration: underline; }
.text-muted { color: var(--gray-11); }
.text-subtle { color: var(--gray-9); }
.fw-500 { font-weight: 500; }

.user-initials { width: 24px; height: 24px; border-radius: var(--radius-2); display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 600; color: #fff; flex-shrink: 0; }
.user-initials.active { background: var(--accent-9); }
.user-initials.inactive { background: var(--gray-8); }

/* --- Timeout Modal --- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center; z-index: 1000; backdrop-filter: blur(4px); }
.modal-card { background: #fff; border-radius: var(--radius-5); padding: 32px; width: 380px; text-align: center; box-shadow: var(--shadow-3); }
.modal-icon { width: 48px; height: 48px; border-radius: 50%; display: flex; align-items: center; justify-content: center; margin: 0 auto 16px; }
.modal-icon.warning { background: var(--amber-3); }
.modal-title { margin: 0 0 8px; font-size: var(--fs-3); font-weight: 600; color: var(--gray-12); }
.modal-text { margin: 0 0 4px; font-size: 13px; color: var(--gray-11); }
.modal-timer { margin: 0 0 24px; font-size: 28px; font-weight: 600; color: var(--gray-12); font-family: var(--font-mono); letter-spacing: -0.02em; }
.modal-actions { display: flex; gap: 8px; }

/* --- Empty state --- */
.empty-state { display: flex; align-items: center; justify-content: center; min-height: 400px; text-align: center; }
.empty-state-icon { width: 48px; height: 48px; border-radius: var(--radius-4); background: var(--gray-3); display: flex; align-items: center; justify-content: center; margin: 0 auto 16px; color: var(--gray-9); }
.empty-state h2 { margin: 0 0 4px; font-size: var(--fs-4); font-weight: 600; }
.empty-state p { margin: 0 0 16px; font-size: 13px; color: var(--gray-9); }

/* --- Role/Perm --- */
.role-filters { display: flex; gap: 6px; padding: 12px 16px; border-bottom: 1px solid var(--gray-4); }
.role-btn { padding: 5px 14px; font-size: 12px; cursor: pointer; border-radius: var(--radius-2); border: 1px solid var(--gray-7); background: var(--gray-1); color: var(--gray-11); font-family: inherit; font-weight: 500; transition: all 0.15s; }
.role-btn.active { background: var(--accent-9); color: var(--accent-contrast); border-color: var(--accent-9); }

.perm-select { font-size: 11px; font-weight: 500; padding: 2px 8px; border-radius: var(--radius-6); border: 1px solid var(--gray-6); cursor: pointer; font-family: inherit; }
.perm-admin { background: #dcfce7; color: #15803d; }
.perm-operate { background: #dbeafe; color: #2563eb; }
.perm-read { background: var(--gray-3); color: var(--gray-11); }
.perm-none { background: transparent; color: var(--gray-7); }

/* --- Error box (login) --- */
.error-box { background: var(--red-3); border: 1px solid rgba(229,72,77,0.2); border-radius: var(--radius-2); padding: 8px 12px; font-size: 12px; color: var(--red-11); margin-bottom: 16px; display: none; }
.error-box.visible { display: block; }

/* --- Responsive --- */
@media (max-width: 768px) {
  .module-grid { grid-template-columns: 1fr; }
  .stat-grid-3, .stat-grid-4 { grid-template-columns: repeat(2, 1fr); }
  .portal-wrapper { padding: 24px 16px; }
  .topbar-user-info { display: none; }
}
