/*
 *= require_tree .
 *= require_self
 */

/* ================================
   BASE RESET
   ================================ */

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

body {
  font-family: Arial, sans-serif;
  font-size: 14px;
  background: #f5f5f3;
  color: #1a1a1a;
}

/* Shared primitives */
.ts-control,
.search-bar input,
.search-bar select,
.form-group input,
.form-group select,
.form-group textarea {
  font-size: 13px;
  border-radius: 6px;
  border: 0.5px solid #ddd;
  background: white;
  color: #1a1a1a;
}

.search-bar input:focus,
.search-bar select:focus,
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: #999;
}

.table-actions,
.form-actions,
.page-actions,
.quick-actions {
  display: flex;
  gap: 8px;
  justify-content:space-between;
}

.page-actions form {
  margin: 0;
}

thead th,
.card-header p,
.section-title,
.stat-card-label {
  font-size: 11px;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #888;
}

/* ================================
   TOM SELECT
   ================================ */

.ts-wrapper { width: 100%; }

.ts-control {
  padding: 8px 10px;
  cursor: text;
}

.ts-dropdown {
  font-size: 13px;
  border: 0.5px solid #ddd;
  border-radius: 6px;
  background: white;
  margin-top: 2px;
}

.ts-dropdown .option { padding: 8px 10px; cursor: pointer; }
.ts-dropdown .option:hover,
.ts-dropdown .option.active { background: #f5f5f3; }
.ts-dropdown .selected { background: #f0f0ee; font-weight: bold; }

/* ================================
   NAVBAR
   ================================ */

.navbar {
  background: white;
  border-bottom: 0.5px solid #ddd;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.navbar-left {
  display: flex;
  align-items: center;
  gap: 2rem;
}

.navbar-brand {
  font-size: 14px;
  font-weight: bold;
  color: #1a1a1a;
  text-decoration: none;
  border-right: 0.5px solid #ddd;
  padding-right: 2rem;
}

.navbar-links {
  display: flex;
  align-items: center;
  gap: 4px;
}

.navbar-links a {
  font-size: 13px;
  color: #666;
  padding: 6px 12px;
  border-radius: 6px;
  text-decoration: none;
}

.navbar-links a:hover { background: #f5f5f3; color: #1a1a1a; }
.navbar-links a.active { background: #f0f0ee; color: #1a1a1a; font-weight: bold; }

.navbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.navbar-user {
  font-size: 12px;
  color: #888;
}

.navbar-logout {
  font-size: 12px;
  color: #666;
  padding: 5px 10px;
  border-radius: 6px;
  border: 0.5px solid #ddd;
  text-decoration: none;
  background: white;
  cursor: pointer;
}

.navbar-logout:hover { background: #f5f5f3; }

/* Hamburger button - hidden on desktop */
.navbar-toggle {
  display: none;
  background: none;
  border: 0.5px solid #ddd;
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 16px;
  color: #666;
}

/* ================================
   LAYOUT
   ================================ */

.main-content {
  padding: 1.5rem;
  max-width: 1200px;
  margin: 0 auto;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

.page-header h1 {
  font-size: 20px;
  font-weight: bold;
}

.page-header p {
  font-size: 13px;
  color: #888;
  margin-top: 2px;
}

/* ================================
   BUTTONS
   ================================ */

.btn {
  font-size: 13px;
  padding: 7px 14px;
  border-radius: 6px;
  border: 0.5px solid #ddd;
  background: white;
  cursor: pointer;
  text-decoration: none;
  color: #1a1a1a;
  display: inline-block;
}

.btn:hover { background: #f5f5f3; }

.btn-primary { background: #1a1a1a; color: white; border-color: #1a1a1a; }
.btn-primary:hover { background: #333; }

.btn-danger { background: white; color: #c0392b; border-color: #e0b0ad; }
.btn-danger:hover { background: #fdf0ef; }

/* ================================
   CARDS & TABLES
   ================================ */

.card {
  background: white;
  border: 0.5px solid #ddd;
  border-radius: 8px;
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  text-align: left;
  padding: 10px 16px;
  border-bottom: 0.5px solid #eee;
  background: #fafaf9;
}

tbody td {
  padding: 12px 16px;
  border-bottom: 0.5px solid #f0f0f0;
  color: #1a1a1a;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #fafaf9; }

.table-actions a {
  font-size: 12px;
  color: #666;
  text-decoration: none;
  padding: 3px 8px;
  border-radius: 4px;
  border: 0.5px solid #eee;
}

.table-actions a:hover { background: #f5f5f3; color: #1a1a1a; }
.table-actions a.danger { color: #c0392b; border-color: #e0b0ad; }
.table-actions a.danger:hover { background: #fdf0ef; }

/* ================================
   SEARCH BAR
   ================================ */

.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 1rem;
  align-items: center;
}

.search-bar form {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  width: 100%;
}

.search-bar input, .search-bar select {
  padding: 7px 10px;
}

/* ================================
   FLASH MESSAGES
   ================================ */

.flash {
  padding: 10px 16px;
  border-radius: 6px;
  margin-bottom: 1rem;
  font-size: 13px;
}

.flash-notice { background: #eaf3de; color: #3b6d11; border: 0.5px solid #c0dd97; }
.flash-alert { background: #fcebeb; color: #a32d2d; border: 0.5px solid #f7c1c1; }

/* ================================
   FORMS
   ================================ */

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

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: bold;
  color: #666;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 8px 10px;
  box-sizing: border-box;
}

.form-group textarea { min-height: 80px; resize: vertical; }

.form-errors {
  background: #fcebeb;
  border: 0.5px solid #f7c1c1;
  border-radius: 6px;
  padding: 10px 16px;
  margin-bottom: 1rem;
  font-size: 13px;
  color: #a32d2d;
}

.form-actions {
  margin-top: 1.5rem;
}

.two-col-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 1.5rem;
}

/* ================================
   EXPIRY BANNER
   ================================ */

.expiry-banner {
  background: #fff8e6;
  border-bottom: 0.5px solid #f0d080;
  padding: 10px 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.expiry-banner-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.expiry-banner-icon { font-size: 16px; }

.expiry-banner-title {
  font-size: 13px;
  font-weight: bold;
  color: #7a5c00;
  margin-bottom: 2px;
}

.expiry-banner-products {
  font-size: 12px;
  color: #7a5c00;
}

.expiry-tag {
  display: inline-block;
  background: #fde68a;
  border: 0.5px solid #f0d080;
  border-radius: 4px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: bold;
  color: #7a5c00;
  margin-right: 2px;
}

a.expiry-tag { text-decoration: none; cursor: pointer; }
a.expiry-tag:hover { background: #fbbf24; }

.expiry-banner-close {
  font-size: 20px;
  color: #999;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0 4px;
  line-height: 1;
  flex-shrink: 0;
}

.expiry-banner-close:hover { color: #555; }

/* ================================
   PAGINATION
   ================================ */

.pagy {
  display: flex;
  gap: 4px;
  align-items: center;
  list-style: none;
}

.pagy a, .pagy span {
  font-size: 13px;
  padding: 5px 10px;
  border-radius: 6px;
  border: 0.5px solid #ddd;
  background: white;
  color: #1a1a1a;
  text-decoration: none;
  display: inline-block;
}

.pagy a:hover { background: #f5f5f3; }
.pagy span.current { background: #1a1a1a; color: white; border-color: #1a1a1a; font-weight: bold; }
.pagy span.gap { border: none; background: none; color: #888; }

/* ================================
   LOGIN
   ================================ */

.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f5f5f3;
  padding: 1.5rem;
  margin: -1.5rem;
}

.login-card {
  background: white;
  border: 0.5px solid #ddd;
  border-radius: 12px;
  padding: 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.06);
}

.login-header {
  text-align: center;
  margin-bottom: 1.5rem;
}

.login-logo {
  max-height: 60px;
  max-width: 200px;
  object-fit: contain;
  margin-bottom: 0.75rem;
}

.login-brand {
  font-size: 20px;
  font-weight: bold;
  color: #1a1a1a;
  margin-bottom: 0.5rem;
}

.login-subtitle { font-size: 13px; color: #888; }

.login-submit {
  width: 100%;
  text-align: center;
  margin-top: 0.5rem;
  padding: 9px;
}

.login-footer {
  text-align: center;
  margin-top: 1.25rem;
  font-size: 12px;
}

.login-footer a { color: #888; text-decoration: none; }
.login-footer a:hover { color: #1a1a1a; }

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

.card-padded {
  padding: 1.25rem;
}

.card-header {
  padding: 10px 16px;
  border-bottom: 0.5px solid #eee;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fafaf9;
}

.card-header a {
  font-size: 12px;
  color: #666;
  text-decoration: none;
}

.card-body {
  padding: 0.75rem 1rem;
}

.table-scroll {
  width: 100%;
}

.mobile-list {
  display: none;
}

.mobile-list-item {
  background: white;
  border: 0.5px solid #ddd;
  border-radius: 8px;
  padding: 0.9rem;
}

.mobile-list-item.is-muted {
  background: #fff8f8;
  color: #777;
}

.mobile-list-header {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: flex-start;
  margin-bottom: 0.65rem;
}

.mobile-list-title {
  font-size: 14px;
  font-weight: bold;
  line-height: 1.3;
}

.mobile-list-subtitle {
  font-size: 12px;
  color: #888;
  margin-top: 2px;
}

.mobile-list-fields {
  display: grid;
  gap: 0.45rem;
  margin-bottom: 0.85rem;
}

.mobile-list-field {
  font-size: 13px;
  line-height: 1.35;
}

.mobile-list-field span {
  display: block;
  font-size: 10px;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #888;
  margin-bottom: 1px;
}

.mobile-list-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.mobile-list-actions .btn {
  padding: 6px 10px;
  font-size: 12px;
}

.section-title {
  border-bottom: 0.5px solid #eee;
  padding-bottom: 6px;
  margin-bottom: 12px;
}

.quick-actions {
  margin-bottom: 1.25rem;
}

.client-actions {
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* Stat cards */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.stat-card-label {
  margin-bottom: 6px;
}

.stat-card-value {
  font-size: 32px;
  font-weight: bold;
  line-height: 1;
  margin-bottom: 4px;
}

.stat-card-sub {
  font-size: 12px;
  color: #888;
}

.stat-card-warning {
  border-color: #f0d080;
  background: #fff8e6;
}

.stat-card-warning .stat-card-label,
.stat-card-warning .stat-card-sub { color: #a07c00; }

.stat-card-warning .stat-card-value { color: #7a5c00; }

/* Dashboard main grid */
.dashboard-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1rem;
}

.dashboard-sidebar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* List items (expiry, renewals) */
.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 0.5px solid #f0f0f0;
}

.list-item:last-child { border-bottom: none; }

.list-item-title {
  font-weight: bold;
  font-size: 13px;
}

.list-item-sub {
  font-size: 11px;
  color: #888;
}

.badge {
  display: inline-block;
  font-size: 10px;
  font-weight: bold;
  padding: 2px 7px;
  border-radius: 4px;
}

.badge-warning {
  background: #fde68a;
  color: #7a5c00;
  border: 0.5px solid #f0d080;
}

.badge-danger {
  background: #fee2e2;
  color: #991b1b;
  border: 0.5px solid #fca5a5;
}

/* Work order show */
.work-order-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.work-order-product-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.product-details-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px 1.5rem;
}

.span-full { grid-column: span 2; }

.td-muted { color: #888; }
.td-link { font-size: 12px; color: #666; }

/* ================================
   MOBILE (max-width: 768px)
   ================================ */

@media (max-width: 768px) {

  .stat-grid { grid-template-columns: 1fr; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .work-order-grid { grid-template-columns: 1fr; }
  .work-order-product-grid { grid-template-columns: 1fr 1fr; }
  .product-details-grid { grid-template-columns: 1fr; }
  .responsive-table { display: none; }
  .mobile-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }
  .span-full { grid-column: span 1; }
  .page-actions { flex-wrap: wrap; }
  .page-actions .btn { flex: 1; text-align: center; }
  .quick-actions { flex-wrap: wrap; }
  .quick-actions .btn { flex: 1; text-align: center; }

  /* Navbar */
  .navbar {
    flex-direction: row;
    flex-wrap: wrap;
    height: auto;
    padding: 0.75rem 1rem;
  }

  .navbar-left {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 0;
  }

  .navbar-brand {
    border-right: none;
    padding: 0;
  }

  .navbar-toggle { display: block; }

  .navbar-links {
    display: none;
    width: 100%;
    flex-direction: column;
    gap: 4px;
    padding-top: 0.75rem;
    border-top: 0.5px solid #eee;
    margin-top: 0.75rem;
    align-items: flex-start;
  }

  .navbar-links.open { display: flex; }

  .navbar-links a {
    padding: 10px 12px;
    font-size: 14px;
  }

  .navbar-right {
    width: 100%;
    justify-content: space-between;
    border-top: 0.5px solid #eee;
    padding-top: 0.75rem;
    margin-top: 0.75rem;
  }

  /* Layout */
  .main-content { padding: 1rem; }

  /* Page header */
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .page-header > .btn,
  .form-actions .btn,
  .search-bar .btn,
  .no-print .btn {
    width: 100%;
    text-align: center;
  }

  .client-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .client-actions .btn {
    width: auto;
    padding: 7px 12px;
  }

  /* Buttons */
  .btn { padding: 10px 14px; }

  /* Forms */
  .two-col-form { grid-template-columns: 1fr; }

  .two-col-form .form-group[style*="grid-column: span 2"] {
    grid-column: span 1 !important;
  }

  .form-actions { flex-direction: column; }

  /* Form cards - no horizontal overflow */
  .card[style*="padding"] { overflow-x: hidden; }

  /* Table cards - allow horizontal scroll */
  .card:has(table) { overflow-x: auto; }
  .card:has(.table-scroll) { overflow-x: hidden; }
  .table-scroll { overflow-x: auto; }
  .card table { min-width: 600px; }

  /* Search bar */
  .search-bar { flex-wrap: wrap; }
  .search-bar form { flex-direction: column; align-items: stretch; }
  .search-bar input, .search-bar select { width: 100% !important; }

  /* Table actions */
  .table-actions { flex-direction: column; gap: 4px; }
  .table-actions a { text-align: center; }

  /* Dashboard grids */
  div[style*="grid-template-columns: 2fr 1fr"] { display: block !important; }
  div[style*="grid-template-columns: 2fr 1fr"] > div { margin-bottom: 1rem; }
  div[style*="grid-template-columns: 1fr 1fr"] { grid-template-columns: 1fr !important; }
  div[style*="grid-template-columns:1fr 1fr"] { grid-template-columns: 1fr !important; }

  /* Work order show */
  div[style*="grid-template-columns: 1fr 1fr; gap: 1rem"] { grid-template-columns: 1fr !important; }
  div[style*="grid-template-columns: repeat(4, 1fr)"] { grid-template-columns: 1fr 1fr !important; }

  /* Signature checkboxes */
  div[style*="display:flex; gap:1.5rem; align-items:center"] {
    flex-direction: column !important;
    gap: 0.5rem !important;
    align-items: flex-start !important;
  }

  /* Expiry banner */
  .expiry-banner { flex-direction: row; align-items: flex-start; }
  .expiry-banner-close { margin-left: auto; }

  /* Login */
  .login-wrapper { padding: 1rem; margin: -1rem; }
  .login-card { padding: 1.5rem 1.25rem; }

  /* Print buttons */
  .no-print { flex-direction: column; }
}

/* ================================
   TABLET (769px - 1024px)
   ================================ */

@media (max-width: 1024px) and (min-width: 769px) {
  .navbar-links a { font-size: 12px; padding: 5px 8px; }
  .main-content { padding: 1.25rem; }
  .two-col-form { grid-template-columns: 1fr 1fr; }
}
