/* =====================================================================
 * THE BOTTLE DEPOT · OPERATIONS HUB
 * Brand stylesheet · v1.0
 * Strictly follows the Brand Book (DIN typography, primary/secondary palette)
 * ===================================================================== */

/* --- Brand display font ---
   Note: The brand book specifies DIN. DIN is a paid font, so we use
   Barlow Condensed for display weights (closest free DIN-style alternative)
   and Inter for body text. Both load from Google Fonts. */
@import url('https://fonts.googleapis.com/css2?family=Barlow+Condensed:wght@400;700;800;900&family=Inter:wght@400;500;700&display=swap');

/* =====================================================================
 * DESIGN TOKENS  (CSS variables)
 * Light theme is default. Dark mode flips automatically.
 * ===================================================================== */
:root {
  /* PRIMARY palette · Brand Book */
  --tbd-white:   #FFFFFF;
  --tbd-light:   #F2F2F2;
  --tbd-gray:    #999999;
  --tbd-dark:    #444347;
  --tbd-black:   #000000;

  /* SECONDARY palette · Brand Book */
  --tbd-yellow:        #FFAF1A;
  --tbd-yellow-bright: #FFE101;
  --tbd-purple:        #734FD5;
  --tbd-purple-light:  #8C64F0;
  --tbd-purple-deep:   #5A3ABA;
  --tbd-coral:         #FF7D32;

  /* Semantic tokens */
  --bg:          var(--tbd-light);
  --surface:     var(--tbd-white);
  --surface-2:   #FAFAFA;
  --border:      rgba(0,0,0,0.08);
  --border-2:    rgba(0,0,0,0.15);
  --text:        var(--tbd-black);
  --text-2:      #5A5A5C;
  --text-3:      var(--tbd-gray);
  --accent:      var(--tbd-yellow);
  --accent-text: var(--tbd-black);
  --topbar-bg:   var(--tbd-black);
  --topbar-text: var(--tbd-white);

  --success-bg:  #E8F6EE;
  --success-text:#1A6B3A;
  --danger-bg:   #FCE9E9;
  --danger-text: #B22323;
  --warning-bg:  #FFF4DA;
  --warning-text:#8A5A0B;
  --info-bg:     #ECE5FB;
  --info-text:   #4A2E9E;

  /* Radii */
  --r-sm:  4px;
  --r-md:  6px;
  --r-lg:  8px;
  --r-xl:  12px;

  /* Shadows · used sparingly */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.08);

  /* Fonts */
  --font-display: 'Barlow Condensed', 'Inter', system-ui, -apple-system, sans-serif;
  --font-body:    'Inter', system-ui, -apple-system, sans-serif;
}

[data-theme='dark'] {
  --bg:          #0A0A0B;
  --surface:     #141416;
  --surface-2:   #1C1C1F;
  --border:      rgba(255,255,255,0.08);
  --border-2:    rgba(255,255,255,0.15);
  --text:        #F2F2F2;
  --text-2:      #B5B5B8;
  --text-3:      #7A7A7E;
  --topbar-bg:   #000000;
  --topbar-text: #FFFFFF;
  --success-bg:  #1A3A28;
  --success-text:#7FD9A4;
  --danger-bg:   #3F1A1A;
  --danger-text: #F09595;
  --warning-bg:  #3D2E0E;
  --warning-text:#F5C765;
  --info-bg:     #2A1F4A;
  --info-text:   #B5A0F0;
}

/* =====================================================================
 * BASE
 * ===================================================================== */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-weight: 400;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4 { font-weight: 700; letter-spacing: -0.01em; margin: 0; font-family: var(--font-display); }
h1 { font-size: 24px; font-weight: 900; letter-spacing: 0.5px; }
h2 { font-size: 19px; font-weight: 800; }
h3 { font-size: 14px; text-transform: uppercase; letter-spacing: 0.8px; font-weight: 700; }

a { color: inherit; text-decoration: none; }

/* =====================================================================
 * TYPOGRAPHY UTILITIES  (matches Brand Book text hierarchy)
 * ===================================================================== */
.t-display { font-family: var(--font-display); font-weight: 900; font-size: 54px; line-height: 1; letter-spacing: 0.5px; text-transform: uppercase; }
.t-h1      { font-family: var(--font-display); font-weight: 900; font-size: 24px; letter-spacing: 0.5px; }
.t-h2      { font-family: var(--font-display); font-weight: 800; font-size: 19px; }
.t-h3      { font-family: var(--font-display); font-weight: 700; font-size: 14px; text-transform: uppercase; letter-spacing: 0.8px; }
.t-body    { font-weight: 400; font-size: 14px; }
.t-small   { font-weight: 400; font-size: 12px; color: var(--text-2); }
.t-meta    { font-weight: 400; font-size: 11px; color: var(--text-3); letter-spacing: 0.3px; }

/* =====================================================================
 * COMPONENTS
 * ===================================================================== */

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--r-md);
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 13px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, transform 0.05s;
  user-select: none;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--tbd-black);
  color: var(--tbd-white);
}
.btn-primary:hover { background: var(--tbd-dark); }

[data-theme='dark'] .btn-primary {
  background: var(--tbd-white);
  color: var(--tbd-black);
}
[data-theme='dark'] .btn-primary:hover { background: var(--tbd-light); }

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

.btn-ghost {
  background: transparent;
  color: var(--text-2);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-danger {
  background: var(--danger-bg);
  color: var(--danger-text);
}

/* Inputs */
.input, .select, .textarea {
  width: 100%;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--r-md);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
  outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--tbd-black);
  box-shadow: 0 0 0 3px rgba(0,0,0,0.05);
}
[data-theme='dark'] .input:focus, [data-theme='dark'] .select:focus, [data-theme='dark'] .textarea:focus {
  border-color: var(--tbd-white);
  box-shadow: 0 0 0 3px rgba(255,255,255,0.06);
}

.input-icon-wrap { position: relative; }
.input-icon-wrap .input { padding-left: 34px; }
.input-icon-wrap > svg {
  position: absolute;
  left: 10px; top: 50%;
  transform: translateY(-50%);
  width: 16px; height: 16px;
  color: var(--text-3);
  pointer-events: none;
}

/* Pills / badges */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-2);
  border: 1px solid var(--border);
}
.pill-success { background: var(--success-bg); color: var(--success-text); border-color: transparent; }
.pill-danger  { background: var(--danger-bg);  color: var(--danger-text);  border-color: transparent; }
.pill-warning { background: var(--warning-bg); color: var(--warning-text); border-color: transparent; }
.pill-info    { background: var(--info-bg);    color: var(--info-text);    border-color: transparent; }

/* Card surface */
.surface {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}

/* =====================================================================
 * APP LAYOUT
 * ===================================================================== */
.layout {
  display: grid;
  grid-template-rows: 48px 1fr;
  height: 100vh;
}
.topbar {
  background: var(--topbar-bg);
  color: var(--topbar-text);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.topbar-brand {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--font-display);
  font-weight: 900; font-size: 15px;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.topbar-brand img { height: 22px; width: auto; filter: invert(1); }
[data-theme='dark'] .topbar-brand img { filter: none; }

.topbar-search {
  flex: 1; max-width: 420px; position: relative;
}
.topbar-search input {
  width: 100%; padding: 7px 10px 7px 32px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--r-md);
  color: var(--topbar-text);
  font-size: 13px;
  font-family: var(--font-body);
  outline: none;
}
.topbar-search input::placeholder { color: rgba(255,255,255,0.5); }
.topbar-search input:focus { background: rgba(255,255,255,0.12); border-color: rgba(255,255,255,0.25); }
.topbar-search > svg {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  width: 14px; height: 14px; color: rgba(255,255,255,0.6); pointer-events: none;
}

.topbar-actions { display: flex; align-items: center; gap: 10px; }
.topbar-actions .icon-btn {
  width: 30px; height: 30px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--r-md);
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  background: transparent; border: none;
}
.topbar-actions .icon-btn:hover { background: rgba(255,255,255,0.08); color: #fff; }

.avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--tbd-yellow);
  color: var(--tbd-black);
  font-weight: 900; font-size: 12px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  border: 1px solid rgba(0,0,0,0.1);
}

/* Main */
.main {
  display: grid;
  grid-template-columns: 200px 1fr;
  min-height: 0;
  overflow: hidden;
}
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  overflow-y: auto;
}
.sidebar-section { margin-bottom: 16px; }
.sidebar-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-3);
  letter-spacing: 1.2px;
  text-transform: uppercase;
  padding: 0 10px;
  margin-bottom: 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px;
  border-radius: var(--r-md);
  font-size: 13px;
  font-weight: 400;
  color: var(--text-2);
  cursor: pointer;
  user-select: none;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active {
  background: var(--tbd-black);
  color: var(--tbd-white);
  font-weight: 700;
}
[data-theme='dark'] .nav-item.active { background: var(--tbd-white); color: var(--tbd-black); }
.nav-item .count {
  margin-left: auto;
  font-size: 11px;
  opacity: 0.6;
}
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }

.content {
  overflow-y: auto;
  padding: 20px 28px;
}

/* =====================================================================
 * APP CARDS  (the heart of the dashboard)
 * ===================================================================== */
.grid-apps {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
}
.grid-pinned {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 8px;
}

.app-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 14px;
  cursor: pointer;
  transition: border-color 0.12s, transform 0.08s, box-shadow 0.12s;
  text-align: left;
  display: block;
  color: inherit;
}
.app-card:hover {
  border-color: var(--border-2);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}
.app-card-icon {
  width: 38px; height: 38px;
  border-radius: var(--r-md);
  background: var(--tbd-black);
  color: var(--tbd-white);
  display: inline-flex; align-items: center; justify-content: center;
  margin-bottom: 10px;
}
.app-card-icon svg { width: 20px; height: 20px; }
.app-card-icon img { width: 24px; height: 24px; }
.app-card-title {
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 2px;
  color: var(--text);
}
.app-card-desc {
  font-size: 11px;
  color: var(--text-2);
  line-height: 1.4;
}
.app-card-star {
  position: absolute; top: 8px; right: 8px;
  width: 22px; height: 22px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--r-sm);
  color: var(--text-3);
  cursor: pointer;
  background: transparent; border: none;
}
.app-card-star:hover { background: var(--surface-2); color: var(--tbd-yellow); }
.app-card-star.is-fav { color: var(--tbd-yellow); }
.app-card-star svg { width: 14px; height: 14px; }
.app-card-badge {
  position: absolute; top: 8px; right: 32px;
  background: #E24B4A; color: #fff;
  font-size: 9px; font-weight: 900;
  padding: 2px 6px;
  border-radius: 999px;
  letter-spacing: 0.3px;
}
.app-card-ext {
  position: absolute; bottom: 10px; right: 10px;
  color: var(--text-3);
}
.app-card-ext svg { width: 12px; height: 12px; }

/* Compact pinned card */
.pin-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 12px 8px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.12s, transform 0.08s;
}
.pin-card:hover { border-color: var(--border-2); transform: translateY(-1px); }
.pin-card-icon {
  width: 30px; height: 30px; margin: 0 auto 6px;
  border-radius: var(--r-md);
  background: var(--tbd-black); color: var(--tbd-white);
  display: flex; align-items: center; justify-content: center;
}
.pin-card-icon svg { width: 16px; height: 16px; }
.pin-card-icon img { width: 20px; height: 20px; }
.pin-card-title { font-size: 11px; font-weight: 700; color: var(--text); }

/* =====================================================================
 * TABLES  (admin)
 * ===================================================================== */
.tbl {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.tbl-row {
  display: grid;
  align-items: center;
  padding: 10px 14px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.tbl-row:last-child { border-bottom: none; }
.tbl-row.header {
  background: var(--surface-2);
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-2);
}

/* =====================================================================
 * MODAL
 * ===================================================================== */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
  padding: 20px;
}
.modal {
  background: var(--surface);
  border-radius: var(--r-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
}
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-body  { padding: 20px; }
.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
}

/* =====================================================================
 * TOASTS
 * ===================================================================== */
#toast-host {
  position: fixed; bottom: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 60;
}
.toast {
  background: var(--tbd-black);
  color: var(--tbd-white);
  padding: 10px 14px;
  border-radius: var(--r-md);
  font-size: 13px;
  font-weight: 700;
  box-shadow: var(--shadow-md);
  animation: toast-in 0.18s ease-out;
}
.toast.success { background: var(--success-bg); color: var(--success-text); }
.toast.danger  { background: var(--danger-bg);  color: var(--danger-text); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* =====================================================================
 * EMPTY / LOADING
 * ===================================================================== */
.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-3);
}
.empty svg { width: 32px; height: 32px; margin-bottom: 10px; opacity: 0.5; }

.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border-2);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =====================================================================
 * RESPONSIVE
 * ===================================================================== */
@media (max-width: 880px) {
  .main { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 48px 0 0 -240px;
    width: 240px;
    transition: left 0.18s;
    z-index: 40;
    box-shadow: var(--shadow-md);
  }
  .sidebar.open { left: 0; }
  .topbar-search { max-width: none; }
  .content { padding: 14px; }
  .grid-apps { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .grid-pinned { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
}
@media (max-width: 520px) {
  .topbar-search { display: none; }
  .grid-apps { grid-template-columns: repeat(2, 1fr); }
  .grid-pinned { grid-template-columns: repeat(3, 1fr); }
}

/* Mobile menu toggle (hidden on desktop) */
.menu-toggle {
  display: none;
  background: transparent; border: none;
  color: rgba(255,255,255,0.7);
  width: 30px; height: 30px;
  align-items: center; justify-content: center;
  border-radius: var(--r-md); cursor: pointer;
}
.menu-toggle svg { width: 16px; height: 16px; }
@media (max-width: 880px) {
  .menu-toggle { display: inline-flex; }
}

/* Utility */
.hidden { display: none !important; }
.flex { display: flex; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.ml-auto { margin-left: auto; }
.w-full { width: 100%; }
