/* ==========================================================================
   G&C Central Deal and Brokerage Automation Platform - Design System
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600;700&family=Outfit:wght@500;600;700;800&display=swap');

:root {
  --bg-primary: #090d16;
  --bg-secondary: #0f172a;
  --bg-tertiary: #1e293b;
  --bg-card: rgba(15, 23, 42, 0.75);
  --bg-card-hover: rgba(30, 41, 59, 0.9);
  --bg-glass: rgba(15, 23, 42, 0.65);
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-medium: rgba(255, 255, 255, 0.15);
  --border-focus: #f59e0b;
  --border-gold-light: rgba(245, 158, 11, 0.4);
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-gold: #fbbf24;
  --accent-gold: #f59e0b;
  --accent-gold-hover: #d97706;
  --accent-gold-glow: rgba(245, 158, 11, 0.25);
  --profit-green: #10b981;
  --profit-green-bg: rgba(16, 185, 129, 0.12);
  --profit-green-border: rgba(16, 185, 129, 0.3);
  --loss-red: #ef4444;
  --loss-red-bg: rgba(239, 68, 68, 0.12);
  --loss-red-border: rgba(239, 68, 68, 0.3);
  --danger-red: #ef4444;
  --info-blue: #38bdf8;
  --info-blue-bg: rgba(56, 189, 248, 0.12);
  --warning-amber: #fbbf24;
  --warning-amber-bg: rgba(251, 191, 36, 0.12);
  --font-display: 'Outfit', sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.2), 0 2px 4px -2px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 10px 25px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -4px rgba(0, 0, 0, 0.3);
  --shadow-gold: 0 0 20px rgba(245, 158, 11, 0.15);
  --shadow-card: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-smooth: 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  --transition-sidebar: 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

body.light-theme {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f1f5f9;
  --bg-card: rgba(255, 255, 255, 0.85);
  --bg-card-hover: #ffffff;
  --bg-glass: rgba(255, 255, 255, 0.75);
  --border-subtle: rgba(0, 0, 0, 0.08);
  --border-medium: rgba(0, 0, 0, 0.15);
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --text-gold: #b45309;
  --shadow-card: 0 8px 32px 0 rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 10px 25px -3px rgba(0, 0, 0, 0.1);
}

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

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

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

.sidebar {
  width: 260px;
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 100;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  transition: transform var(--transition-sidebar);
  will-change: transform;
}

.main-content {
  margin-left: 260px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow-x: hidden;
}

.top-header {
  height: 64px;
  background-color: var(--bg-glass);
  border-bottom: 1px solid var(--border-subtle);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  gap: 12px;
  flex-wrap: wrap;
}

.page-body {
  padding: 24px;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
}

/* Hamburger Toggle */
.sidebar-toggle-btn {
  display: none;
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 1050;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: #1e293b;
  border: 1px solid var(--border-gold-light);
  color: var(--text-gold);
  font-size: 1.25rem;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background var(--transition-fast), transform var(--transition-fast);
}

.sidebar-toggle-btn:active {
  transform: scale(0.93);
  background: #0f172a;
}

/* Sidebar Overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 1040;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  cursor: pointer;
}

/* Typography - fluid */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
  overflow-wrap: break-word;
  word-break: break-word;
}

h1 { font-size: clamp(1.25rem, 4vw, 1.75rem); }
h2 { font-size: clamp(1.1rem, 3.5vw, 1.375rem); }
h3, h4, h5, h6 { font-size: clamp(0.95rem, 3vw, 1.125rem); }

.font-mono { font-family: var(--font-mono); }
.text-gold { color: var(--text-gold); }
.text-profit { color: var(--profit-green); }
.text-loss { color: var(--loss-red); }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 600;
  padding: 8px 16px;
  min-height: 40px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  border: 1px solid transparent;
  text-decoration: none;
  white-space: nowrap;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent-gold), #d97706);
  color: #0f172a;
  box-shadow: 0 2px 10px var(--accent-gold-glow);
}
.btn-primary:hover {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px var(--accent-gold-glow);
}

.btn-glass-success {
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.15), rgba(16, 185, 129, 0.05));
  color: #4ade80;
  border: 1px solid rgba(34, 197, 94, 0.3);
  box-shadow: 0 4px 12px rgba(34, 197, 94, 0.1);
  backdrop-filter: blur(4px);
  font-weight: 600;
}
.btn-glass-success:hover {
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.25), rgba(16, 185, 129, 0.15));
  border-color: rgba(34, 197, 94, 0.5);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(34, 197, 94, 0.2);
  color: #86efac;
}

.btn-glass-gold {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.1), rgba(217, 119, 6, 0.05));
  color: var(--text-gold);
  border: 1px solid rgba(245, 158, 11, 0.3);
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.05);
  backdrop-filter: blur(4px);
  font-weight: 600;
}
.btn-glass-gold:hover {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.2), rgba(217, 119, 6, 0.1));
  border-color: var(--accent-gold);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(245, 158, 11, 0.15);
  color: #fbbf24;
}

.btn-glass-primary {
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.15), rgba(59, 130, 246, 0.05));
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.3);
  box-shadow: 0 4px 12px rgba(56, 189, 248, 0.1);
  backdrop-filter: blur(4px);
  font-weight: 600;
}
.btn-glass-primary:hover {
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.25), rgba(59, 130, 246, 0.15));
  border-color: rgba(56, 189, 248, 0.5);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(56, 189, 248, 0.2);
  color: #7dd3fc;
}

.btn-glass-default {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  border: 1px solid var(--border-medium);
  backdrop-filter: blur(4px);
  font-weight: 600;
}
.btn-glass-default:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--text-muted);
  transform: translateY(-1px);
}

.btn-solid-success {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
  font-weight: 600;
}
.btn-solid-success:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(16, 185, 129, 0.4);
  color: #ffffff;
}

.btn-secondary {
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--border-medium);
}
.btn-secondary:hover {
  background-color: rgba(255, 255, 255, 0.1);
  border-color: var(--border-focus);
}

.btn-success { background: linear-gradient(135deg, #10b981, #059669); color: #ffffff; }
.btn-danger { background: linear-gradient(135deg, #ef4444, #dc2626); color: #ffffff; }

.btn-outline-gold {
  background: transparent;
  color: var(--text-gold);
  border-color: var(--accent-gold);
}
.btn-outline-gold:hover { background: var(--accent-gold-glow); }

.btn-outline-danger {
  background: transparent;
  color: var(--danger-red);
  border: 1px solid rgba(239, 68, 68, 0.4);
}
.btn-outline-danger:hover {
  background: var(--loss-red-bg);
  border-color: var(--danger-red);
}

.btn-sm {
  padding: 5px 12px;
  font-size: 0.75rem;
  min-height: 32px;
  border-radius: var(--radius-sm);
}

.btn-lg {
  padding: 12px 24px;
  font-size: 1rem;
  min-height: 48px;
  border-radius: var(--radius-md);
}

/* Form Controls */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.form-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.form-label .unit-badge {
  font-size: 0.7rem;
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  color: var(--accent-gold);
}

.form-control, .form-select {
  font-family: var(--font-body);
  font-size: 0.875rem;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-medium);
  color: var(--text-primary);
  padding: 10px 14px;
  min-height: 44px;
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  width: 100%;
}

.form-control:focus, .form-select:focus {
  border-color: var(--accent-gold);
  box-shadow: 0 0 0 3px var(--accent-gold-glow);
}

.form-control::placeholder { color: var(--text-muted); }

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--shadow-card);
  padding: 20px;
  transition: transform var(--transition-fast), border-color var(--transition-fast);
}
.card:hover { border-color: var(--border-medium); }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-subtle);
}

.card-title {
  font-size: clamp(0.95rem, 2.5vw, 1.125rem);
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  font-size: 0.7rem;
  font-weight: 600;
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
  flex-shrink: 0;
}

.badge-profit, .badge-completed, .badge-synced {
  background-color: var(--profit-green-bg);
  color: var(--profit-green);
  border: 1px solid var(--profit-green-border);
}
.badge-loss, .badge-cancelled, .badge-failed {
  background-color: var(--loss-red-bg);
  color: var(--loss-red);
  border: 1px solid var(--loss-red-border);
}
.badge-confirmed, .badge-ready, .badge-in_progress {
  background-color: var(--warning-amber-bg);
  color: var(--warning-amber);
  border: 1px solid rgba(245, 158, 11, 0.3);
}
.badge-info, .badge-draft {
  background-color: var(--info-blue-bg);
  color: var(--info-blue);
  border: 1px solid rgba(56, 189, 248, 0.3);
}

/* Tables */
.table-responsive, .table-wrapper {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  margin-bottom: 1rem;
  border-radius: var(--radius-md);
}

.table-responsive table, .table-wrapper table { min-width: 600px; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  text-align: left;
}

.data-table th {
  background-color: var(--bg-tertiary);
  color: var(--text-secondary);
  font-weight: 600;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-medium);
  white-space: nowrap;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
  vertical-align: middle;
}

.data-table tr:hover td { background-color: rgba(255, 255, 255, 0.02); }

td div[style*="display: flex"] { flex-wrap: wrap; gap: 6px; }

/* Toast */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1200;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: calc(100vw - 32px);
}

.toast {
  background: var(--bg-secondary);
  border: 1px solid var(--border-medium);
  border-left: 4px solid var(--accent-gold);
  border-radius: var(--radius-md);
  padding: 12px 18px;
  box-shadow: var(--shadow-lg);
  color: var(--text-primary);
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 260px;
  max-width: min(450px, calc(100vw - 32px));
  animation: slideIn 0.3s ease;
  word-break: break-word;
}

.toast.toast-success { border-left-color: var(--profit-green); }
.toast.toast-error { border-left-color: var(--loss-red); }

/* ===== RESPONSIVE BREAKPOINTS ===== */

/* Tablet & Small Laptop (≤1024px) */
@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
    z-index: 1100;
    box-shadow: none;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 32px rgba(0,0,0,0.7);
  }
  .sidebar-overlay { display: none; }
  .sidebar-overlay.visible { display: block; }
  .main-content { margin-left: 0; }
  .sidebar-toggle-btn { display: flex; }
  .page-body { padding: 16px; }
  .top-header { padding-left: 64px; }
}

/* Tablet Portrait (≤768px) */
@media (max-width: 768px) {
  .page-body { padding: 14px; }
  .card { padding: 16px; }
  .top-header {
    height: auto;
    min-height: 56px;
    padding: 8px 12px 8px 62px;
    gap: 8px;
    flex-wrap: wrap;
  }
  .modal-container {
    width: 95vw !important;
    max-width: 95vw !important;
    margin: 16px auto !important;
    max-height: 90vh !important;
  }
}

/* Large Phone (≤640px) */
@media (max-width: 640px) {
  .page-body { padding: 10px; }
  .top-header {
    padding: 8px 10px 8px 60px;
    min-height: 52px;
    height: auto;
    gap: 6px;
  }
  .top-header .text-secondary { display: none !important; }
  .toast-container { bottom: 12px; right: 8px; left: 8px; max-width: none; }
  .toast { min-width: unset; max-width: 100%; font-size: 0.8125rem; }
  .form-control, .form-select {
    font-size: 16px !important;
    min-height: 46px;
    padding: 10px 12px;
  }
  .btn-lg { width: 100%; justify-content: center; }
  .modal-container {
    width: 97vw !important;
    max-width: 97vw !important;
    margin: 8px auto !important;
    max-height: 94vh !important;
    border-radius: var(--radius-lg) !important;
  }
  .modal-body { padding: 16px !important; }
  .modal-footer {
    padding: 12px 16px !important;
    flex-wrap: wrap;
    gap: 8px;
  }
  .modal-footer .btn { flex: 1; min-width: 120px; justify-content: center; }
}

/* Standard Phone (≤480px) */
@media (max-width: 480px) {
  .page-body { padding: 8px; }
  .card { padding: 14px; border-radius: var(--radius-md); }
  .card-header { flex-direction: column; align-items: flex-start; gap: 10px; }
  .card-header .btn { align-self: flex-end; }
  .btn-sm { min-height: 36px; padding: 6px 12px; }
  .top-header { padding: 6px 8px 6px 58px; }
}

/* Small Phone (≤360px) */
@media (max-width: 360px) {
  .page-body { padding: 6px; }
  .card { padding: 12px; }
  .btn { font-size: 0.8125rem; padding: 7px 12px; }
  .top-header { padding: 4px 6px 4px 56px; }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Print */
@media print {
  .sidebar-toggle-btn, .sidebar-overlay { display: none !important; }
}
