/* ============================================
   TKM Web App - Root (theme, base, shared components)
   ============================================ */

/* ---------- Theme: Light (default) ---------- */
:root,
[data-theme="light"] {
  --sidebar-bg: #1f2438;
  --sidebar-text: #e8eaed;
  --sidebar-text-active: #fff;
  --sidebar-accent: #5b9bd5;
  --main-bg: #dbdbdb;
  --surface: #ffffff;
  --surface-2: #f0f1f3;
  --surface-alt: #f8f9fa;
  --bg-subtle: #f8f9f8;
  --text-primary: #1a1d24;
  --text-secondary: #5f6368;
  --text-muted: #80868b;
  --border: #dadce0;
  --border-light: #e8eaed;
  --accent: #2e7d32;
  --accent-hover: #1b5e20;
  --accent-light: #e8f5e9;
  --accent-blue: #5b9bd5;
  --order-bar: #1a5f4a;
  --danger: #c62828;
  --danger-hover: #b71c1c;
  --chart-green: #2e7d32;
  --chart-green-light: #81c784;
  --chart-muted: #e0e0e0;
  --shadow: rgba(0, 0, 0, 0.08);
  --footer-bg: #1a1d24;
  --footer-text: #e8eaed;
  /* Auth (login) glass & background */
  --auth-pattern: url('../images/diagmonds-light.png');
  --auth-glass-bg: rgba(255, 255, 255, 0);
  --auth-glass-border: rgba(255, 255, 255, 0.35);
  --auth-glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  --auth-bg-icon-opacity: 0.5;
}

/* ---------- Scrollbars (theme-aware, app-wide) ---------- */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) var(--surface-2);
}

*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

*::-webkit-scrollbar-track {
  background: var(--surface-2);
  border-radius: 4px;
}

*::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

*::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

*::-webkit-scrollbar-corner {
  background: var(--surface-2);
}

/* ---------- Theme: Dark ---------- */
[data-theme="dark"] {
  --main-bg: #121212;
  --surface: #1e1e1e;
  --surface-2: #2d2d2d;
  --surface-alt: #2d2d2d;
  --bg-subtle: #252525;
  --text-primary: #e8eaed;
  --text-secondary: #9aa0a6;
  --text-muted: #80868b;
  --border: #3c4043;
  --border-light: #3c4043;
  --accent: #4caf50;
  --accent-hover: #66bb6a;
  --accent-light: #1e3b20;
  --order-bar: #2d6b5a;
  --danger-hover: #e57373;
  --chart-green: #4caf50;
  --chart-green-light: #66bb6a;
  --chart-muted: #3c4043;
  --shadow: rgba(0, 0, 0, 0.3);
  /* Auth (login) glass & background */
  --auth-pattern: url('../images/diagmonds.png');
  --auth-glass-bg: rgba(30, 30, 30, 0);
  --auth-glass-border: rgba(255, 255, 255, 0.08);
  --auth-glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --auth-bg-icon-opacity: 0.5;
}

/* ---------- Base ---------- */
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--main-bg);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
}

a {
  color: var(--accent-blue);
}

a:hover {
  text-decoration: underline;
}

/* ---------- App layout (main area) ---------- */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.top-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border-light);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-shrink: 0;
}

.top-header .header-spacer {
  flex: 1;
}

.top-header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Profile trigger and dropdown */
.header-profile-wrap {
  position: relative;
}

.user-widget.js-profile-trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.75rem 0.5rem 1rem;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  color: inherit;
  transition: background 0.2s, border-color 0.2s;
}

.user-widget.js-profile-trigger:hover {
  background: var(--surface-2);
  border-color: var(--text-muted);
}

.user-widget-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.3;
}

.user-widget.js-profile-trigger .user-widget-name,
.user-widget .name {
  font-weight: 600;
  font-size: 0.9375rem;
  color: var(--text-primary);
}

.user-widget.js-profile-trigger .user-widget-email,
.user-widget .email {
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.header-profile-chevron {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-left: 0.25rem;
}

.header-profile-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 160px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 12px var(--shadow);
  padding: 0.25rem 0;
  z-index: 50;
}

.header-profile-menu[hidden] {
  display: none;
}

.header-profile-menu-item {
  display: block;
  padding: 0.5rem 1rem;
  font-size: 0.9375rem;
  color: var(--text-primary);
  text-decoration: none;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
}

.header-profile-menu-item:hover {
  background: var(--surface-2);
}

.user-widget {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 1rem;
  text-align: right;
}

.user-widget .name {
  font-weight: 600;
  font-size: 0.9375rem;
  color: var(--text-primary);
}

.user-widget .email {
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.page-content {
  flex: 1;
  padding: 1.5rem;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0 0 1.25rem;
  color: var(--text-primary);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  font-size: 0.9375rem;
  font-weight: 500;
  font-family: inherit;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text-primary);
  border-color: var(--border);
}

.btn-secondary:hover {
  background: var(--surface-2);
  border-color: var(--text-muted);
}

.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.875rem;
}

/* ---------- Form controls ---------- */
.input,
select.input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 0.9375rem;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input:focus,
select.input:focus {
  outline: none;
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(91, 155, 213, 0.2);
}

.input::placeholder {
  color: var(--text-muted);
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.375rem;
  color: var(--text-primary);
}

.search-wrap {
  display: flex;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 0.75rem;
}

.search-wrap .input {
  border: none;
  background: transparent;
  padding: 0.5rem 0.25rem;
}

.search-wrap .input:focus {
  box-shadow: none;
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
  box-shadow: 0 1px 3px var(--shadow);
}

.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
  box-shadow: 0 1px 3px var(--shadow);
}

.metric-card .value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.metric-card .label {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.metric-card .badge {
  display: inline-block;
  font-size: 0.75rem;
  padding: 0.125rem 0.5rem;
  background: var(--surface-2);
  color: var(--text-secondary);
  border-radius: 6px;
  margin-top: 0.5rem;
}

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.tab {
  padding: 0.5rem 1rem;
  font-size: 0.9375rem;
  font-weight: 500;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

.tab:hover {
  background: var(--surface-2);
  color: var(--text-primary);
}

.tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ---------- Table ---------- */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 1px 3px var(--shadow);
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
}

table.data-table th,
table.data-table td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border-light);
}

table.data-table th {
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--surface-2);
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

table.data-table tr:last-child td {
  border-bottom: none;
}

table.data-table tr:hover td {
  background: var(--surface-2);
}

table.data-table .text-right {
  text-align: right;
}

/* ---------- Metric grid ---------- */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

/* ---------- Chart ---------- */
.chart-bars {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  height: 160px;
  padding: 1rem 0;
}

.chart-bar {
  flex: 1;
  min-width: 24px;
  border-radius: 6px 6px 0 0;
  background: var(--chart-muted);
  min-height: 8px;
  transition: height 0.3s;
}

.chart-bar.high {
  background: var(--chart-green);
}

.chart-bar.mid {
  background: var(--chart-green-light);
}

.chart-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

/* ---------- TKM layout (customer/employee) ---------- */
.tkm-layout {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--main-bg);
}

.tkm-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1.5rem;
  text-align: center;
}

.tkm-logo {
  font-weight: 800;
  font-size: 1.5rem;
  letter-spacing: 0.02em;
  color: var(--text-primary);
  margin: 0;
}

.tkm-tagline {
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin: 0.25rem 0 0;
}

.tkm-main {
  flex: 1;
  padding: 1.5rem;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

.tkm-footer {
  background: var(--footer-bg);
  color: var(--footer-text);
  padding: 1.25rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}

.tkm-footer .brand {
  font-weight: 700;
  font-size: 0.9375rem;
}

.tkm-footer .contact {
  font-size: 0.875rem;
  text-align: right;
}

.tkm-footer .contact a {
  color: var(--footer-text);
}

/* ---------- Theme toggle: single button (Light/Dark) – same look everywhere (header + fixed) ---------- */
.theme-toggle-fixed {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 100;
}

/* Single shared appearance for both header (employee-order, company-admin) and fixed (login, accept-invite) */
.theme-toggle-single {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  min-width: 5.5rem;
  padding: 0.55rem 1.15rem;
  font-size: 0.9375rem;
  font-weight: 600;
  font-family: inherit;
  letter-spacing: 0.02em;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-primary);
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.theme-toggle-single:hover {
  background: var(--surface-2);
  border-color: var(--text-muted);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
}

.theme-toggle-single:focus-visible {
  outline: 2px solid var(--accent-blue, #5b9bd5);
  outline-offset: 2px;
}

.theme-toggle-single:active {
  transform: scale(0.98);
}

[data-theme="dark"] .theme-toggle-single {
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .theme-toggle-single:hover {
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.55);
}

/* ---------- Password field with show/hide (app-wide) ---------- */
.password-input-wrap {
  display: flex;
  align-items: stretch;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  overflow: hidden;
  margin-bottom: 10px;
}

.password-input-wrap .input {
  flex: 1;
  border: none;
  border-radius: 0;
}

.password-toggle-btn {
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-left: 1px solid var(--border);
  cursor: pointer;
  white-space: nowrap;
}

.password-toggle-btn:hover {
  color: var(--text-primary);
  background: var(--surface-2);
}

/* ---------- Utilities ---------- */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mt-2 { margin-top: 1rem; }
.text-right { text-align: right; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* ---------- Response modal (replaces alert) ---------- */
.response-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 1rem;
}

.response-modal-overlay[hidden] {
  display: none !important;
}

.response-modal.card {
  max-width: 480px;
  width: 100%;
  max-height: 85vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  border-radius: 12px;
}

.response-modal-title {
  margin: 0 0 0.75rem;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  flex-shrink: 0;
}

.response-modal-body {
  overflow-y: auto;
  flex: 0 1 auto;
  margin-bottom: 0;
  font-size: 0.9375rem;
  color: var(--text-primary);
  line-height: 1.5;
}

.response-modal-body p {
  margin: 0 0 0.75rem;
  color: var(--text-secondary);
}

.response-modal-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.response-modal-actions .btn {
  min-width: 6rem;
}

/* Order confirm list inside response modal */
.response-modal-body .order-confirm-list {
  list-style: none;
  padding: 0;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.response-modal-body .order-confirm-list li {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9375rem;
  color: var(--text-primary);
}

.response-modal-body .order-confirm-list li:last-child {
  border-bottom: none;
}

.response-modal-body .order-confirm-list li strong {
  display: inline-block;
  min-width: 5.5rem;
  color: var(--text-secondary);
  font-weight: 600;
}

.response-modal-overlay:focus-within .response-modal { outline: none; }
.response-modal-error-intro { margin: 0.5rem 0 0.25rem; font-size: 0.9rem; color: var(--text-secondary); }
.response-modal-table-wrap { overflow-x: auto; max-height: 200px; overflow-y: auto; border: 1px solid var(--border); border-radius: 4px; }
.response-modal-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.response-modal-table th,
.response-modal-table td { padding: 0.4rem 0.5rem; text-align: left; border-bottom: 1px solid var(--border-light); }
.response-modal-table th { background: var(--surface-2); font-weight: 600; }
.response-modal-table tbody tr:last-child td { border-bottom: none; }

.app-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.app-footer-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.powered-by-banner {
  padding: 0.5rem 1.5rem;
  background: var(--surface-2);
  border-top: 1px solid var(--border-light);
  color: var(--text-secondary);
  font-size: 0.8125rem;
}

.powered-by-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.powered-by-label {
  opacity: 0.9;
}

.powered-by-link {
  color: var(--accent-blue, #5b9bd5);
  text-decoration: none;
  font-weight: 600;
}

.powered-by-link:hover {
  text-decoration: underline;
}

/* ---------- Loading modal (theme-aware) ---------- */
.loading-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(2px);
}

.loading-modal-overlay[hidden] {
  display: none !important;
}

.loading-modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem 2rem;
  box-shadow: 0 8px 32px var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  min-width: 200px;
}

.loading-modal-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent, #2e7d32);
  border-radius: 50%;
  animation: loading-modal-spin 0.7s linear infinite;
}

@keyframes loading-modal-spin {
  to { transform: rotate(360deg); }
}

.loading-modal-message {
  margin: 0;
  font-size: 0.9375rem;
  color: var(--text-secondary);
}

/* ---------- Responsive (root) ---------- */
@media (max-width: 768px) {
  .app-layout {
    flex-direction: column;
  }

  .metric-grid {
    grid-template-columns: 1fr 1fr;
  }

  .page-content {
    padding: 1rem;
  }
}
