@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,600;9..144,700&family=Work+Sans:wght@400;500;600;700&family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  /* JKR TEX brand palette (from the logo): red badge + multicolour horse */
  --brand-red: #e11b22;
  --brand-red-dark: #b3141a;
  --brand-green: #3aaa35;
  --brand-green-dark: #2e8a2a;
  --brand-orange: #f07e26;
  --brand-orange-dark: #d2661a;
  --brand-blue: #1d71b8;
  --brand-blue-dark: #155a93;

  /* token names inherited from upstream, re-pointed at the JKR palette */
  --cream-100: #ffffff;
  --cream-200: #e9ebf1;
  --gold: #e11b22;
  --gold-light: #f2a3a6;
  --brown-500: #f07e26;
  --brown-700: #d2661a;
  --accent: #e11b22;

  --jkr-ink: #1a1a26;   /* dark ink: headings, login labels */
  --jkr-red-900: #7d0d12;
  --jkr-red-700: #b3141a;
  --jkr-red-500: #e11b22;
  --jkr-red-400: #ef3a41;

  /* app design system */
  --ink-900: #14141f;
  --ink-800: #1d1d2c;
  --ink-700: #26263a;
  --muted-nav: #9797ab;
  --page-bg: #f4f4f7;
  --border: #e5e7ef;
  --text-900: #1a1a26;
  --text-600: #63637a;

  --blue-500: #e11b22;   /* primary = brand red (name kept so every rule follows) */
  --blue-700: #b3141a;
  --purple-500: #1d71b8; /* secondary buttons = brand blue */
  --purple-700: #155a93;
  --green-600: #3aaa35;
  --green-800: #2e8a2a;
  --rose-500: #f07e26;   /* attention / pending = brand orange */
  --rose-700: #d2661a;

  --success: #2e8a2a;
  --error: #c4141d;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 10px rgba(20,20,31,0.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Inter', 'Work Sans', system-ui, -apple-system, sans-serif;
  background: var(--page-bg);
  color: var(--text-900);
}
h1, h2, h3 { font-weight: 700; }
.login-panel h2, .sidebar-brand .brand-text { font-family: 'Fraunces', Georgia, serif; }
a { text-decoration: none; color: inherit; }

.app-shell { display: flex; min-height: 100vh; }

/* Sidebar — white, JKR red active state */
.sidebar {
  width: 250px;
  background: #ffffff;
  color: var(--text-900);
  border-right: 1px solid var(--cream-200);
  flex-shrink: 0;
  transition: width .2s ease;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .6rem;
  padding: 1.5rem 1.25rem 1.25rem;
  white-space: nowrap;
  border-bottom: 1px solid var(--cream-200);
  margin-bottom: .5rem;
}
.sidebar-brand img { max-width: 180px; width: 100%; height: auto; object-fit: contain; flex-shrink: 0; }
.sidebar-brand .brand-text { display: none; }

.sidebar-nav { display: flex; flex-direction: column; gap: .2rem; padding: .5rem .9rem; flex: 1; }
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: .85rem;
  padding: 0.65rem .9rem;
  font-size: 0.92rem;
  font-weight: 500;
  color: #4a4a5f;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}
.sidebar-nav a .icon { display: inline-flex; flex-shrink: 0; }
.sidebar-nav a:hover { background: rgba(225,27,34,0.07); color: var(--text-900); }
.sidebar-nav a.active { background: var(--blue-500); color: #fff; font-weight: 700; box-shadow: 0 4px 14px rgba(225,27,34,0.30); }

.sidebar-subnav { display: flex; flex-direction: column; padding-left: 2.3rem; }
.sidebar-subnav a { padding: .45rem .5rem; font-size: .85rem; color: #4a4a5f; }
.sidebar-subnav a:before { content: '•'; margin-right: .5rem; }
.sidebar-subnav a:hover, .sidebar-subnav a.active { color: var(--blue-700); }

/* Collapsed = icon rail only */
.sidebar.collapsed { width: 76px; }
.sidebar.collapsed .brand-text,
.sidebar.collapsed .nav-label { opacity: 0; width: 0; overflow: hidden; }
.sidebar.collapsed .sidebar-nav a { justify-content: center; padding: 0.65rem 0; }
.sidebar.collapsed .sidebar-subnav { display: none; }
.sidebar.collapsed .sidebar-brand { padding: 1rem .5rem; }
.sidebar.collapsed .sidebar-brand img { max-width: 46px; }

/* Main */
.app-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  min-height: 68px;
  background: #fff;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.75rem;
  gap: 1rem;
}
.topbar-left { display: flex; align-items: center; gap: .9rem; }
.sidebar-toggle {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 30px;
  height: 30px;
  font-size: 1rem;
  cursor: pointer;
  color: var(--text-600);
  display: flex;
  align-items: center;
  justify-content: center;
}
.topbar-greeting { line-height: 1.35; }
.topbar-greeting .greeting-line { font-weight: 700; font-size: 1rem; color: var(--text-900); }
.topbar-greeting .company-line { font-size: .78rem; font-weight: 700; letter-spacing: .04em; color: var(--text-600); text-transform: uppercase; }

.topbar-right { display: flex; align-items: center; gap: 1rem; }
.topbar-user small { color: var(--text-600); }
.topbar-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--blue-500); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .9rem; flex-shrink: 0;
}
.btn-logout {
  background: var(--ink-800);
  color: #fff;
  padding: 0.45rem 0.95rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}

.content { padding: 1.75rem; flex: 1; }

.alert { padding: 0.75rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1rem; font-size: 0.9rem; }
.alert-success { background: #e4f5ec; color: var(--success); border: 1px solid #b7e3c9; }
.alert-error { background: #fce8ec; color: var(--error); border: 1px solid #f4c1cd; }

/* Cards / stats */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 1.1rem; margin-bottom: 1.5rem; }
.stat-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.4rem;
}
a.stat-card { display: block; transition: transform .12s ease, box-shadow .12s ease; }
a.stat-card:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(20,20,31,0.16); }
.stat-card .stat-icon {
  width: 40px; height: 40px; border-radius: 10px;
  background: rgba(255,255,255,0.25);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; margin-bottom: 1rem;
}
.stat-card .label { font-size: 0.82rem; color: var(--text-600); font-weight: 600; }
.stat-card .value { font-size: 1.9rem; font-weight: 800; color: var(--text-900); margin-top: .2rem; }

.stat-card.stat-blue { background: linear-gradient(135deg, #ef3a41, #b3141a); }
.stat-card.stat-green { background: linear-gradient(135deg, #54c24f, #2e8a2a); }
.stat-card.stat-rose { background: linear-gradient(135deg, #f79445, #d2661a); }
.stat-card.stat-purple { background: linear-gradient(135deg, #3d90d6, #155a93); }
.stat-card.stat-gold { background: linear-gradient(135deg, #f79445, #f07e26); }
.stat-card.stat-blue .label, .stat-card.stat-green .label, .stat-card.stat-rose .label, .stat-card.stat-purple .label, .stat-card.stat-gold .label { color: rgba(255,255,255,0.85); }
.stat-card.stat-blue .value, .stat-card.stat-green .value, .stat-card.stat-rose .value, .stat-card.stat-purple .value, .stat-card.stat-gold .value { color: #fff; }

.site-footer {
  padding: 1.25rem 1.75rem;
  text-align: center;
  font-size: .82rem;
  color: var(--text-600);
  border-top: 1px solid var(--border);
}
.site-footer a { color: var(--blue-700); font-weight: 600; }

.card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.5rem; }
.page-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.25rem; flex-wrap: wrap; gap: .75rem; }
.page-head h2 { font-size: 1.4rem; }
.page-head .page-sub { color: var(--text-600); font-size: .85rem; margin-top: .15rem; }
.page-head-actions { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }

.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.search-combo { display: flex; }
.search-combo input {
  min-width: 260px; padding: .6rem .9rem; border: 1px solid var(--border);
  border-right: none; border-radius: var(--radius-sm) 0 0 var(--radius-sm); font-size: .88rem; background: #fff;
}
.search-combo button {
  background: var(--blue-500); color: #fff; border: none; padding: 0 1rem;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0; cursor: pointer;
}
.filter-select {
  padding: .6rem .9rem; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: #fff; font-size: .88rem; color: var(--text-900);
}

table.data-table { width: 100%; border-collapse: collapse; background: #fff; border-radius: var(--radius); overflow: hidden; }
table.data-table th, table.data-table td { padding: 0.8rem 1.1rem; text-align: left; border-bottom: 1px solid var(--border); font-size: 0.88rem; }
table.data-table th { background: #eef0f6; font-weight: 700; color: var(--text-900); font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
table.data-table tbody tr:hover { background: #f7f8fb; }

.pill { display: inline-block; padding: .3rem .75rem; border-radius: 20px; font-size: .74rem; font-weight: 700; color: #fff; white-space: nowrap; }
.pill-red { background: #e4434a; }
.pill-green { background: #2e8a2a; }
.pill-blue { background: #1d71b8; }
.pill-purple { background: #6a4bd0; }
.pill-gray { background: #9797ab; }
.pill-gold { background: #f07e26; }

.pagination { display: flex; align-items: center; gap: .35rem; justify-content: flex-end; margin-top: 1rem; flex-wrap: wrap; }
.pagination a, .pagination span {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 32px; height: 32px; padding: 0 .5rem; border-radius: var(--radius-sm);
  font-size: .85rem; color: var(--text-600); border: 1px solid transparent;
}
.pagination a:hover { background: #eef0f6; }
.pagination .current { background: var(--blue-500); color: #fff; font-weight: 700; }
.pagination select { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .35rem .5rem; font-size: .82rem; margin-left: .5rem; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  background: var(--blue-500);
  color: #fff;
  border: none;
  padding: 0.65rem 1.15rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
}
.btn:hover { background: var(--blue-700); }
.btn-purple { background: var(--purple-500); }
.btn-purple:hover { background: var(--purple-700); }
.btn-outline { background: #fff; color: var(--text-900); border: 1px solid var(--border); }
.btn-outline:hover { background: #f2f3f7; }
.btn-danger { background: var(--rose-500); }
.btn-danger:hover { background: var(--rose-700); }

.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 0.35rem; color: var(--text-900); }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 0.6rem 0.75rem; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 0.9rem; background: #fff;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { outline: 2px solid var(--blue-500); outline-offset: 1px; }

/* Conversations — two-pane master/detail */
.conv-grid { display: flex; gap: 1.25rem; align-items: stretch; height: calc(100vh - 230px); min-height: 480px; }
.conv-list-card { width: 340px; flex-shrink: 0; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden; }
.conv-list-header { display: flex; justify-content: space-between; align-items: center; padding: 1.1rem 1.25rem; border-bottom: 1px solid var(--border); font-weight: 700; }
.conv-search { padding: .75rem 1.1rem; }
.conv-search input { width: 100%; padding: .55rem .8rem; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: .85rem; }
.conv-items { flex: 1; overflow-y: auto; }
.conv-item { display: flex; align-items: center; gap: .75rem; padding: .75rem 1.25rem; border-bottom: 1px solid var(--border); }
.conv-item:hover { background: #f7f8fb; }
.conv-item.active { background: #fdecec; }
.conv-avatar { width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: .9rem; flex-shrink: 0; }
.conv-meta { flex: 1; min-width: 0; }
.conv-name { font-weight: 600; font-size: .88rem; }
.conv-sub { font-size: .78rem; color: var(--text-600); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 190px; }
.conv-time { font-size: .7rem; color: var(--text-600); flex-shrink: 0; }

.conv-panel-card { flex: 1; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden; }
.conv-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; background: #fdece0; gap: .6rem; }
.conv-empty h3 { color: var(--text-900); }
.conv-empty p { color: var(--text-600); font-size: .88rem; }

.conv-thread-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); }
.conv-thread-header .conv-name { font-size: 1rem; }
.conv-thread-body { flex: 1; overflow-y: auto; padding: 1.25rem; display: flex; flex-direction: column; gap: .5rem; background: #f7f8fb; }
.conv-thread-footer { padding: 1rem 1.25rem; border-top: 1px solid var(--border); display: flex; gap: .5rem; }
.conv-thread-footer input { flex: 1; padding: .6rem .8rem; border: 1px solid var(--border); border-radius: var(--radius-sm); }

/* Integration / settings tile cards */
.tile-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1.1rem; }
.tile-card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.5rem; text-align: center; }
.tile-card img, .tile-card .tile-icon { width: 75px; height: 75px; object-fit: contain; margin: 0 auto .75rem; display: block; }
.tile-card h3 { font-size: 1rem; }
.tile-card .tile-status { font-size: .82rem; color: var(--text-600); margin: .2rem 0 1rem; }
.tile-card .tile-status.active { color: var(--green-600); font-weight: 600; }

/* Settings menu list */
.settings-row { display: flex; align-items: center; gap: 1rem; padding: 1.1rem 1.5rem; border-bottom: 1px solid var(--border); }
.settings-row:last-child { border-bottom: none; }
.settings-row:hover { background: var(--page-bg); }
.settings-row-icon {
  width: 42px; height: 42px; border-radius: 10px; flex-shrink: 0;
  background: rgba(122,31,61,0.10); color: var(--blue-500);
  display: flex; align-items: center; justify-content: center;
}
.settings-row-text { flex: 1; min-width: 0; }
.settings-row-text h3 { font-size: .95rem; }
.settings-row-text p { font-size: .82rem; color: var(--text-600); margin-top: .15rem; }
.settings-row-arrow { color: var(--text-600); flex-shrink: 0; }

.summary-list { display: flex; flex-direction: column; }
.summary-list .row { display: flex; justify-content: space-between; padding: .65rem 0; border-bottom: 1px solid var(--border); font-size: .88rem; }
.summary-list .row:last-child { border-bottom: none; }
.summary-list .row span:first-child { color: var(--text-600); }
.summary-list .row span:last-child { font-weight: 600; }

/* Split-screen login */
.login-split { min-height: 100vh; display: flex; }
.login-panel {
  flex: 1;
  background: linear-gradient(160deg, var(--brand-red), var(--brand-red-dark));
  color: #fff;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 3rem;
  position: relative;
  overflow: hidden;
}
.login-panel::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    repeating-linear-gradient(45deg, rgba(255,255,255,0.06) 0, rgba(255,255,255,0.06) 2px, transparent 2px, transparent 14px);
  pointer-events: none;
}
.login-illustration { width: 400px; margin-bottom: 1.5rem; position: relative; z-index: 1; }
.login-panel h2 { font-size: 1.7rem; font-weight: 600; text-align: center; margin-bottom: .75rem; position: relative; z-index: 1; }
.login-panel p { text-align: center; color: rgba(255,255,255,0.88); line-height: 1.6; max-width: 340px; position: relative; z-index: 1; }

.login-form-side {
  flex: 1;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 3rem;
  background: #fff;
}
.login-form-side .form-inner { width: 100%; max-width: 360px; }
.login-form-side .login-logo { width: 110px; height: 110px; object-fit: contain; display: block; margin: 0 auto 1rem; }
.login-form-side h1 { font-size: 1.7rem; text-align: center; color: var(--jkr-ink); margin-bottom: .3rem; }
.login-form-side .subtitle { text-align: center; color: #8a8378; font-size: .92rem; margin-bottom: 2rem; }

.input-icon-group { position: relative; margin-bottom: 1.1rem; }
.input-icon-group label { display: block; font-size: .82rem; font-weight: 600; color: var(--jkr-ink); margin-bottom: .4rem; }
.input-icon-group .field-wrap { display: flex; align-items: center; background: var(--cream-100); border: 1px solid var(--cream-200); border-radius: 10px; padding: 0 .9rem; }
.input-icon-group .field-wrap span { color: var(--gold); margin-right: .6rem; font-size: 1rem; }
.input-icon-group input { flex: 1; border: none; background: transparent; padding: .75rem 0; font-size: .95rem; outline: none; }

.btn-login-wide {
  width: 100%;
  background: linear-gradient(135deg, var(--brand-red), var(--brand-red-dark));
  color: #fff;
  border: none;
  padding: .85rem;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: .5rem;
}
.btn-login-wide:hover { background: var(--brand-red-dark); }

.login-footer-credit { text-align: center; margin-top: 1.75rem; font-size: .85rem; color: #8a8378; }
.login-footer-credit a { color: var(--gold); font-weight: 600; }

@media (max-width: 860px) {
  .login-split { flex-direction: column; }
  .login-panel { padding: 2.5rem 1.5rem; min-height: 260px; }
  .login-illustration { width: 160px; height: 160px; }
}

@media (max-width: 860px) {
  .detail-grid { grid-template-columns: 1fr !important; }
}

@media (max-width: 1024px) {
  .sidebar { position: fixed; z-index: 20; top: 0; left: 0; height: 100%; width: 250px; transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); }
  .app-main { width: 100%; }
  .search-combo input { min-width: 0; }
  .conv-grid { flex-direction: column; height: auto; }
  .conv-list-card { width: 100%; height: 340px; }
  .conv-panel-card { min-height: 460px; }
}

@media (max-width: 640px) {
  .content { padding: 1.1rem; }
  .topbar { padding: .75rem 1rem; flex-wrap: wrap; gap: .6rem; }
  .topbar-user { display: none; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .conv-list-card { height: 280px; }
}

@media (max-width: 420px) {
  .stat-grid { grid-template-columns: 1fr; }
}

/* Dashboard: chart + top items */
.dash-grid { display: grid; grid-template-columns: 3fr 2fr; gap: 1.25rem; align-items: start; }
.top-items { max-height: 290px; overflow-y: auto; padding-right: .25rem; }
.top-item { display: grid; grid-template-columns: 1fr 52px 96px; gap: .75rem; align-items: center; padding: .6rem 0; border-bottom: 1px solid var(--border); font-size: .86rem; }
.top-item:last-child { border-bottom: none; }
.top-item-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-item-num { display: flex; flex-direction: column; line-height: 1.25; }
.top-item-num small { color: var(--text-600); font-size: .7rem; }
@media (max-width: 960px) { .dash-grid { grid-template-columns: 1fr; } }

/* New-order toast */
.jkr-toast-wrap { position: fixed; top: 1rem; right: 1rem; z-index: 90; display: flex; flex-direction: column; gap: .5rem; }
.jkr-toast { background: #fff; border-left: 4px solid var(--gold); box-shadow: 0 8px 28px rgba(20,20,31,.22); border-radius: var(--radius-sm); padding: .75rem 1rem; min-width: 250px; max-width: 340px; animation: jkrIn .25s ease; }
.jkr-toast strong { display: block; font-size: .9rem; }
.jkr-toast span { font-size: .8rem; color: var(--text-600); }
.jkr-toast a { display: inline-block; margin-top: .35rem; font-size: .82rem; font-weight: 600; color: var(--blue-700); }
@keyframes jkrIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* Printable order */
.print-only { display: none; }
@media print {
  .sidebar, .topbar, .site-footer, .no-print, .jkr-toast-wrap, .alert { display: none !important; }
  .app-shell, .app-main, .content { display: block !important; padding: 0 !important; background: #fff !important; }
  body { background: #fff !important; }
  .card { box-shadow: none !important; border: 1px solid #ddd; break-inside: avoid; }
  .detail-grid { display: block !important; }
  .detail-grid > div { margin-bottom: 1rem; }
  .print-only { display: block !important; }
}

/* Order-alert sound toggle (top bar) */
.topbar-icon-btn { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border); background: #fff; color: var(--jkr-red-500); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; }
.topbar-icon-btn:hover { background: var(--page-bg); }
.topbar-icon-btn .bell-slash { display: none; }
.topbar-icon-btn.is-off { color: var(--text-600); }
.topbar-icon-btn.is-off .bell-slash { display: inline; }
