/* ─── Reset & Base ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #1a56db;
  --primary-dark: #1e40af;
  --primary-light: #dbeafe;
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-100);
  color: var(--gray-800);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-user-select: none;
  user-select: none;
}

/* ─── Login Page ──────────────────────────────────────────────────────── */
.login-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #1e3a5f 0%, #1a56db 100%);
}

.login-card {
  background: white;
  border-radius: 12px;
  padding: 40px;
  width: 400px;
  max-width: 90vw;
  box-shadow: var(--shadow-lg);
}

.login-card h1 {
  font-size: 24px;
  color: var(--gray-900);
  margin-bottom: 4px;
}

.login-card .subtitle {
  color: var(--gray-500);
  font-size: 14px;
  margin-bottom: 28px;
}

.login-card .logo-icon {
  width: 48px;
  height: 48px;
  background: var(--primary);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 16px;
}

/* ─── Microsoft SSO Button ────────────────────────────────────────────── */
.btn-microsoft {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 20px;
  background: #ffffff;
  color: #5e5e5e;
  border: 1px solid #8c8c8c;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  width: 100%;
}

.btn-microsoft:hover {
  background: #f5f5f5;
  border-color: #5e5e5e;
  color: #333;
}

.sso-divider {
  display: flex;
  align-items: center;
  margin: 20px 0 16px;
  gap: 12px;
}

.sso-divider::before,
.sso-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--gray-300);
}

.sso-divider span {
  font-size: 12px;
  color: var(--gray-400);
  white-space: nowrap;
}

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

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 6px;
}

input[type="text"],
input[type="password"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--gray-800);
  background: white;
  transition: border-color 0.15s;
  -webkit-user-select: text;
  user-select: text;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

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

.btn-success {
  background: var(--success);
  color: white;
}
.btn-success:hover { opacity: 0.9; }

.btn-danger {
  background: var(--danger);
  color: white;
}
.btn-danger:hover { opacity: 0.9; }

.btn-outline {
  background: white;
  color: var(--gray-700);
  border: 1px solid var(--gray-300);
}
.btn-outline:hover { background: var(--gray-50); }

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

.btn-block {
  width: 100%;
}

/* ─── Layout ──────────────────────────────────────────────────────────── */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  background: var(--gray-900);
  color: white;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--gray-700);
}

.sidebar-header h2 {
  font-size: 16px;
  font-weight: 700;
}

.sidebar-header .tag {
  display: inline-block;
  background: var(--primary);
  color: white;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  margin-top: 4px;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--gray-400);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover {
  color: white;
  background: rgba(255,255,255,0.05);
}

.nav-item.active {
  color: white;
  background: rgba(255,255,255,0.1);
  border-right: 3px solid var(--primary);
}

.nav-item .icon {
  width: 20px;
  text-align: center;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--gray-700);
}

.user-info {
  font-size: 13px;
}

.user-info .name {
  font-weight: 600;
  color: white;
}

.user-info .role {
  color: var(--gray-400);
  font-size: 12px;
  text-transform: capitalize;
}

.logout-btn {
  margin-top: 10px;
  background: none;
  border: 1px solid var(--gray-600);
  color: var(--gray-400);
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 12px;
  cursor: pointer;
  width: 100%;
}

.logout-btn:hover {
  color: white;
  border-color: var(--gray-400);
}

.main-content {
  flex: 1;
  margin-left: 240px;
  padding: 24px 32px;
}

/* ─── Page Header ─────────────────────────────────────────────────────── */
.page-header {
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 24px;
  color: var(--gray-900);
}

.page-header p {
  color: var(--gray-500);
  font-size: 14px;
  margin-top: 2px;
}

/* ─── Search ──────────────────────────────────────────────────────────── */
.search-box {
  background: white;
  border-radius: 12px;
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}

.search-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.search-row .form-group {
  margin-bottom: 0;
}

.search-row .search-input {
  flex: 1;
}

.search-row .search-type {
  width: 200px;
}

.search-notice {
  margin-top: 12px;
  padding: 10px 14px;
  background: #fef3c7;
  border: 1px solid #fcd34d;
  border-radius: var(--radius);
  font-size: 13px;
  color: #92400e;
}

/* ─── Results Table ───────────────────────────────────────────────────── */
.card {
  background: white;
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-header h3 {
  font-size: 16px;
  color: var(--gray-800);
}

.card-body {
  padding: 20px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 12px 16px;
  border-bottom: 1px solid var(--gray-200);
  background: var(--gray-50);
}

td {
  padding: 12px 16px;
  font-size: 14px;
  border-bottom: 1px solid var(--gray-100);
}

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

tr:hover td {
  background: var(--gray-50);
}

.ts-code {
  font-family: 'SF Mono', Monaco, 'Cascadia Mono', monospace;
  font-weight: 600;
  color: var(--primary);
}

.supplier-link {
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  border-bottom: 1px dashed var(--gray-300);
  transition: all 0.15s;
}

.supplier-link:hover {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.supplier-link.ts-code,
td.ts-code .supplier-link {
  color: var(--primary);
  border-bottom-color: var(--primary-light);
}

td.ts-code .supplier-link:hover {
  border-bottom-style: solid;
}

/* ─── Division Checklist ──────────────────────────────────────────── */
.divisions-checklist {
  max-height: 280px;
  overflow-y: auto;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 8px;
  background: var(--gray-50);
}

.division-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  -webkit-user-select: none;
  user-select: none;
  transition: background 0.1s;
}

.division-checkbox:hover {
  background: var(--gray-200);
}

.division-checkbox input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  cursor: pointer;
}

.division-checkbox span {
  flex: 1;
}

.copy-ts-btn {
  padding: 4px 10px !important;
  font-size: 11px !important;
  white-space: nowrap;
  transition: all 0.15s;
}

.copy-ts-btn.btn-success {
  color: white !important;
  border-color: var(--success) !important;
}

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
}

.badge-active {
  background: #d1fae5;
  color: #065f46;
}

.badge-inactive {
  background: #fecaca;
  color: #991b1b;
}

.badge-pending {
  background: #fef3c7;
  color: #92400e;
}

/* ─── Stats Cards ─────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: white;
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.stat-card .stat-label {
  font-size: 13px;
  color: var(--gray-500);
  margin-bottom: 4px;
}

.stat-card .stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--gray-900);
}

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

.empty-state .icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.empty-state p {
  font-size: 14px;
}

/* ─── Alert ───────────────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  margin-bottom: 16px;
}

.alert-error {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.alert-success {
  background: #f0fdf4;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.alert-info {
  background: var(--primary-light);
  color: var(--primary-dark);
  border: 1px solid #93c5fd;
}

/* ─── Modal ───────────────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: white;
  border-radius: 12px;
  padding: 24px;
  width: 500px;
  max-width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal h2 {
  font-size: 18px;
  margin-bottom: 16px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* ─── Pagination ──────────────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px;
}

/* ─── Utility ─────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.text-sm { font-size: 13px; }
.text-muted { color: var(--gray-500); }
.text-right { text-align: right; }
.flex { display: flex; }
.gap-2 { gap: 8px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }

/* ─── Security: Disable print and copy ────────────────────────────────── */
@media print {
  body { display: none !important; }
}

/* ─── Security: Watermark overlay ─────────────────────────────────────── */
.watermark-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  overflow: hidden;
}

.watermark-overlay .wm-text {
  position: absolute;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 600;
  color: rgba(0, 0, 0, 0.06);
  transform: rotate(-30deg);
  letter-spacing: 2px;
  user-select: none;
  -webkit-user-select: none;
}

/* ─── Security: Blur on focus loss ────────────────────────────────────── */
body.blurred .main-content,
body.blurred .sidebar {
  filter: blur(20px);
  transition: filter 0.1s;
}

body.blurred .watermark-overlay {
  display: none;
}

body.blurred::after {
  content: 'Content hidden — return to this window to continue';
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.85);
  font-size: 18px;
  font-weight: 600;
  color: var(--gray-700);
  z-index: 10000;
}

/* ─── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .sidebar-header h2, .sidebar .nav-item span, .user-info, .logout-btn { display: none; }
  .sidebar-header { padding: 16px 12px; }
  .nav-item { justify-content: center; padding: 12px; }
  .main-content { margin-left: 60px; padding: 16px; }
  .search-row { flex-direction: column; }
  .search-row .search-type { width: 100%; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
