/* client/assets/styles/app.css */

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

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--primary); }
a:hover { color: var(--primary-hover); }

/* ── Top navigation bar ─────────────────────────────────────── */
.app-navbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  height: 56px;
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 24px;
  position: sticky; top: 0; z-index: 3000;
}

.app-navbar .brand {
  font-weight: 700;
  font-size: 16px;
  color: var(--primary);
  text-decoration: none;
  margin-right: 16px;
}

.app-navbar .nav-link {
  text-decoration: none;
  color: var(--text);
  font-size: 14px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: background .15s, color .15s;
}

.app-navbar .nav-link:hover,
.app-navbar .nav-link.active {
  background: var(--nav-active-bg);
  color: var(--nav-active-text);
}

.app-navbar .spacer { flex: 1; }

.app-navbar .user-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.notify-wrap { position: relative; margin-right: 10px; }
.notify-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  cursor: pointer;
  color: var(--text);
  font-size: 17px;
}
.notify-btn:hover { color: var(--primary); }
.notify-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #dc3545;
  color: #fff;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
  font-weight: 700;
}
.notify-popover {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: 360px;
  max-width: calc(100vw - 32px);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 12px 28px rgba(0, 0, 0, .18);
  z-index: 3100;
}
.notify-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.notify-list {
  max-height: 420px;
  overflow: auto;
}
.notify-item {
  display: block;
  padding: 10px 12px;
  text-decoration: none;
  color: var(--text);
  background: #f2f4f7;
  border-bottom: 1px solid var(--border);
}
.notify-item:last-child { border-bottom: none; }
.notify-item:hover { background: var(--table-row-hover); }
.notify-item.unread { background: #fff; }
.notify-item-title { font-weight: 600; font-size: 13px; margin-bottom: 3px; }
.notify-item-summary { font-size: 12px; color: var(--text-muted); margin-bottom: 3px; }
.notify-item-time { font-size: 11px; color: var(--text-muted); }

.app-navbar .user-pill {
  background: transparent;
  border-radius: 16px;
  padding: 8px 14px;
  min-width: 260px;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.app-navbar .user-pill-name {
  font-size: 16px;
  font-weight: 500;
  color: #111827;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-navbar .user-pill-scope {
  font-size: 14px;
  color: #4b5563;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Main content area ──────────────────────────────────────── */
.app-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 16px;
}

/* ── Card ───────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.card-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-body { padding: 20px; }

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
  text-decoration: none;
  white-space: nowrap;
}

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

.btn-outline {
  background: transparent;
  color: var(--primary);
  border-color: var(--primary);
}
.btn-outline:hover {
  background: var(--nav-active-bg);
}

.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-danger { background: #dc3545; color: #fff; border-color: #dc3545; }
.btn-danger:hover { background: #bb2d3b; border-color: #bb2d3b; }
.btn-secondary { background: #6c757d; color: #fff; border-color: #6c757d; }

/* ── Tables ─────────────────────────────────────────────────── */
.table-responsive { overflow-x: auto; }

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

.data-table th,
.data-table td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table thead th {
  background: var(--table-header-bg);
  font-weight: 600;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .4px;
  position: sticky; top: 0;
}

.data-table tbody tr:hover { background: var(--table-row-hover); }
.data-table tbody tr.selected { background: var(--table-row-selected); }
.data-table tbody tr:nth-child(even) { background: var(--table-stripe); }
.data-table tbody tr:nth-child(even):hover { background: var(--table-row-hover); }

/* ── Status Badges ──────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .3px;
}

.badge-Draft       { background: #6c757d22; color: #6c757d; }
.badge-Archived    { background: #adb5bd22; color: #6c757d; }
.badge-Submitted   { background: #0d6efd22; color: #0d6efd; }
.badge-Approved    { background: #19875422; color: #198754; }
.badge-Rejected    { background: #dc354522; color: #dc3545; }
.badge-Split       { background: #0dcaf022; color: #0077a0; }
.badge-InProgress  { background: #fd7e1422; color: #c95400; }
.badge-Completed   { background: #19875422; color: #198754; }
.badge-Cancelled   { background: #adb5bd22; color: #6c757d; }
.badge-Exception   { background: #dc354522; color: #dc3545; }
.badge-Open        { background: #0d6efd22; color: #0d6efd; }
.badge-Sourcing    { background: #6f42c122; color: #6f42c1; }
.badge-Quoted      { background: #20c99722; color: #0e7a5a; }
.badge-Purchased   { background: #fd7e1422; color: #c95400; }
.badge-Paid        { background: #19875422; color: #198754; }
.badge-Exporting   { background: #0dcaf022; color: #0077a0; }
.badge-InTransit   { background: #0d6efd22; color: #0d6efd; }
.badge-Arrived     { background: #19875422; color: #198754; }
.badge-Received    { background: #19875422; color: #198754; }
.badge-Closed      { background: #adb5bd22; color: #6c757d; }
.badge-active      { background: #19875422; color: #198754; }
.badge-disabled    { background: #dc354522; color: #dc3545; }

/* ── Forms ──────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 4px;
  color: var(--text);
}

.form-control {
  width: 100%;
  padding: 7px 11px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-2);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(13,110,253,.15);
}

.form-control.is-invalid { border-color: #dc3545; }
.form-text { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
.invalid-feedback { font-size: 12px; color: #dc3545; margin-top: 3px; }

/* ── Toast ──────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 360px;
}

.toast {
  background: #f8f9fa;
  border: 1px solid transparent;
  border-radius: .5rem;
  padding: 12px 16px;
  box-shadow: 0 .5rem 1rem rgba(0,0,0,.12);
  font-size: 13px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  animation: slide-in .2s ease;
}

.toast-success { color:#0f5132; background:#d1e7dd; border-color:#badbcc; }
.toast-error   { color:#842029; background:#f8d7da; border-color:#f5c2c7; }
.toast-info    { color:#055160; background:#cff4fc; border-color:#b6effb; }
.toast-warning { color:#664d03; background:#fff3cd; border-color:#ffecb5; }

@keyframes slide-in {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ── Pagination ─────────────────────────────────────────────── */
.pagination {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-wrap: wrap;
}

.page-btn {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  transition: background .15s;
}

.page-btn:hover { background: var(--table-row-hover); }
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-btn:disabled { opacity: .4; cursor: default; }

/* ── Filter bar ─────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 16px;
}

.filter-bar .form-control {
  width: auto;
  min-width: 140px;
}

/* ── Login page ─────────────────────────────────────────────── */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 16px;
}

.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
}

.login-card .brand-logo {
  display: block;
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 8px;
}

.login-card .subtitle {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 28px;
}

/* ── Loading spinner ────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  vertical-align: middle;
}

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

/* ── Empty state ────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-state svg { opacity: .3; margin-bottom: 12px; }

/* ── Grid (Handsontable container) ──────────────────────────── */
#hot-container {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

/* ── Modal overlay ──────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3200;
  padding: 16px;
}

.modal-box {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-box .modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
}

.modal-box .modal-body { padding: 20px; }
.modal-box .modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.btn-close-modal {
  background: none; border: none;
  font-size: 18px; cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
  padding: 0 4px;
}

/* ── Detail layout ──────────────────────────────────────────── */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px 24px;
  margin-bottom: 20px;
}

.detail-item { }
.detail-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.detail-value { font-size: 14px; font-weight: 500; }

/* ── Timeline (comments) ────────────────────────────────────── */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline-item {
  display: flex;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.timeline-item:last-child { border-bottom: none; }
.timeline-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--nav-active-bg);
  color: var(--nav-active-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}
.timeline-body .author {
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 2px;
}
.timeline-body .time { font-size: 11px; color: var(--text-muted); margin-left: 8px; }
.timeline-body .content { font-size: 13px; }

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  .app-navbar { height: auto; padding: 10px 12px; gap: 12px; flex-wrap: wrap; }
  .app-navbar .brand { margin-right: 0; }
  .app-navbar .user-info { margin-left: auto; width: 100%; justify-content: space-between; }
  .app-navbar .user-pill { min-width: 0; max-width: calc(100% - 86px); }
  .app-navbar .user-pill-name { font-size: 15px; }
  .app-navbar .user-pill-scope { font-size: 13px; }
  .app-main { padding: 16px 12px; }
  .login-card { padding: 24px 20px; }
  .detail-grid { grid-template-columns: 1fr 1fr; }
}
