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

/* ============================================================================
   RECIPROCAL AGREEMENT MANAGEMENT - FULL FIXED THEME CSS
   FIX: Manual toggle always wins (no OS override)
   ============================================================================ */

/* ============================================================================
   1. RESET & BASE
   ============================================================================ */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg-grad), var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a { color: inherit; }

.muted,
.text-muted {
  opacity: 0.75;
  color: var(--muted);
}

/* ============================================================================
   2. THEME VARIABLES
   IMPORTANT: NO prefers-color-scheme (it breaks manual toggle)
   ============================================================================ */

/* DEFAULT = DARK THEME */
:root {
  color-scheme: dark;
  --font: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;

  /* Dark Mode Colors */
  --bg: #0b1220;
  --bg-grad: radial-gradient(900px 320px at 5% -10%, rgba(34,211,238,.10), transparent 60%);
  --panel: #0f172a;
  --topbar-bg: rgba(15,23,42,.92);
  --sidebar-bg: #0f172a;

  --line: rgba(255,255,255,.10);
  --text: #e5e7eb;
  --muted: rgba(229,231,235,.70);

  --nav-hover: rgba(255,255,255,.06);

  --accent: #22d3ee;
  --accent-2: #38bdf8;
  --accent-soft: rgba(34,211,238,.14);

  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;

  --shadow: 0 10px 30px rgba(0,0,0,.30);

  --radius-xl: 16px;
  --radius-lg: 14px;
  --radius-md: 12px;

  --focus: 0 0 0 4px rgba(34,211,238,.16);

  --topbar-h: 64px;

  /* Alias */
  --soft: var(--line);
}

/* MANUAL LIGHT THEME (TOGGLE) */
html[data-theme="light"] {
  color-scheme: light;

  --bg: #f7f8fc;
  --bg-grad: radial-gradient(900px 320px at 5% -10%, rgba(37,99,235,.14), transparent 60%);
  --panel: #ffffff;
  --topbar-bg: rgba(255,255,255,.92);
  --sidebar-bg: #ffffff;

  --line: rgba(15,23,42,.10);
  --text: #0f172a;
  --muted: rgba(15,23,42,.62);

  --nav-hover: rgba(15,23,42,.05);

  --accent: #2563eb;
  --accent-2: #38bdf8;
  --accent-soft: rgba(37,99,235,.12);

  --danger: #dc2626;

  --focus: 0 0 0 4px rgba(37,99,235,.16);

  --soft: var(--line);
}

/* OPTIONAL: Explicit dark (not required, but ok) */
html[data-theme="dark"] {
  color-scheme: dark;
  --soft: var(--line);
}

/* ============================================================================
   3. LAYOUT COMPONENTS
   ============================================================================ */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--topbar-h);
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--line);
  backdrop-filter: saturate(1.15) blur(10px);
}

.topbar .wrap {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  gap: 12px;
}

.brand {
  color: var(--text);
  font-weight: 800;
  letter-spacing: 0.2px;
  font-size: 18px;
  white-space: nowrap;
}

/* Sidebar */
.sidebar {
  position: fixed;
  left: 0;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  width: 270px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--line);
  transform: translateX(-100%);
  transition: transform 0.20s ease;
  z-index: 40;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.sidebar.open { transform: translateX(0); }

.sidebar-header {
  padding: 12px 14px;
  font-weight: 800;
  color: var(--text);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: rgba(0,0,0,.02);
}

html[data-theme="dark"] .sidebar-header {
  background: rgba(255,255,255,.02);
}

.sidebar-scroll {
  flex: 1;
  overflow: auto;
  padding: 6px 0;
}

/* Navigation */
.nav a,
.nav button.linkbtn {
  display: block;
  width: 100%;
  padding: 10px 14px;
  color: var(--muted);
  text-decoration: none;
  border-left: 3px solid transparent;
  font-size: 14px;
  background: transparent;
  text-align: left;
  border: 0;
  cursor: pointer;
}

.nav a:hover,
.nav a.active,
.nav button.linkbtn:hover {
  background: var(--nav-hover);
  color: var(--text);
  border-left-color: var(--accent);
}

/* Overlay */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(2,6,23,.32);
  display: none;
  z-index: 35;
}

html[data-theme="light"] .overlay {
  background: rgba(2,6,23,.22);
}

.overlay.show { display: block; }

/* FAB */
.fab {
  position: fixed;
  left: 16px;
  top: calc(var(--topbar-h) + 12px);
  z-index: 45;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 18px;
  box-shadow: var(--shadow);
}

body.nav-open .fab { display: none; }

/* Main */
.main {
  padding: 18px;
  width: 100%;
  max-width: none;
  margin: 0;
}

.page {
  max-width: 1200px;
  margin: 18px auto;
  padding: 0 12px;
}

/* ============================================================================
   4. CARDS
   ============================================================================ */

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.toolbar,
.header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.02);
}

html[data-theme="light"] .toolbar,
html[data-theme="light"] .header {
  background: rgba(15,23,42,.02);
}

.title,
.header h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
}

.header p {
  margin: 6px 0 0 0;
  color: var(--muted);
  font-size: 13px;
}

/* ============================================================================
   5. BUTTONS
   ============================================================================ */

.btn,
.btn-back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 14px;
  text-decoration: none;
  font-size: 14px;
  font-weight: 800;
  background: transparent;
  color: var(--text);
  border: 1px solid rgba(34,211,238,.55);
  box-shadow: 0 0 0 4px rgba(34,211,238,.10);
  transition: all 0.15s ease;
  cursor: pointer;
}

html[data-theme="light"] .btn,
html[data-theme="light"] .btn-back {
  border-color: rgba(37,99,235,.45);
  box-shadow: 0 0 0 4px rgba(37,99,235,.10);
}

.btn:hover,
.btn-back:hover {
  transform: translateY(-1px);
  border-color: rgba(34,211,238,.95);
  box-shadow: 0 0 0 6px rgba(34,211,238,.14);
}

html[data-theme="light"] .btn:hover,
html[data-theme="light"] .btn-back:hover {
  border-color: rgba(37,99,235,.85);
  box-shadow: 0 0 0 6px rgba(37,99,235,.14);
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  border-color: transparent;
  box-shadow: 0 10px 18px rgba(0,0,0,.12);
}

.btn.primary:hover {
  filter: saturate(1.05);
  transform: translateY(-2px);
}

/* Icon Buttons */
.iconbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.02);
  color: var(--text);
  transition: all 0.15s ease;
  cursor: pointer;
}

.iconbtn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
  stroke: currentColor;
}

.iconbtn:hover {
  background: var(--nav-hover);
  transform: translateY(-1px);
}

.iconbtn.danger {
  border-color: rgba(239,68,68,.55);
}

/* Light Mode Icon Button Specific */
html[data-theme="light"] .iconbtn {
  background: rgba(125,80,255,.10) !important;
  border-color: rgba(125,80,255,.25) !important;
  color: #1e293b !important;
  box-shadow: 0 6px 16px rgba(125,80,255,.10);
}

html[data-theme="light"] .iconbtn:hover {
  background: rgba(125,80,255,.16) !important;
  border-color: rgba(125,80,255,.40) !important;
}

html[data-theme="light"] .iconbtn.danger {
  background: rgba(220,38,38,.10) !important;
  border-color: rgba(220,38,38,.35) !important;
  color: #7f1d1d !important;
}

html[data-theme="light"] .iconbtn.danger:hover {
  background: rgba(220,38,38,.16) !important;
  border-color: rgba(220,38,38,.45) !important;
}

.actions-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
  align-items: center;
}

/* Theme Toggle Button */
.theme-toggle {
  position: fixed;
  bottom: 18px;
  right: 18px;
  width: 54px;
  height: 54px;
  border-radius: 999px;
  border: 0;
  cursor: pointer;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 18px 30px rgba(0,0,0,.18);
  transition: transform 0.15s ease, filter 0.15s ease;
}

.theme-toggle:hover {
  transform: translateY(-2px) scale(1.03);
  filter: saturate(1.05);
}

.theme-toggle svg {
  width: 22px;
  height: 22px;
  fill: #fff;
}

/* ============================================================================
   6. FORMS
   ============================================================================ */

.form-body { padding: 12px 16px 16px 16px; }

.form-grid {
  display: grid;
  gap: 12px;
}

label {
  display: block;
  color: var(--text);
  font-weight: 700;
  font-size: 13px;
}

label .lbl {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-weight: 800;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.inp,
select.inp,
textarea.inp {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  color: var(--text);
  padding: 10px;
  font-size: 14px;
  outline: none;
  transition: all 0.2s ease;
}

html[data-theme="dark"] .inp { background: rgba(15,23,42,.60); }
html[data-theme="light"] .inp { background: rgba(15,23,42,.03); }

.inp::placeholder {
  color: var(--muted);
  opacity: 0.7;
}

.inp:focus {
  box-shadow: var(--focus);
  border-color: rgba(34,211,238,.45);
}

html[data-theme="light"] .inp:focus {
  border-color: rgba(37,99,235,.45);
}

/* ============================================================================
   7. TABLES - GLOBAL
   ============================================================================ */

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 12px;
}

table.table {
  width: 100%;
  border-collapse: separate !important;
  border-spacing: 0 !important;
  border-radius: 12px;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid rgba(125,80,255,.18);
  table-layout: auto;
}

table.table thead {
  background: linear-gradient(90deg,
    rgba(125,80,255,.22),
    rgba(168,85,247,.18),
    rgba(56,189,248,.12)
  );
}

table.table thead th {
  padding: 10px 10px !important;
  font-weight: 900 !important;
  font-size: 0.78rem !important;
  text-transform: uppercase;
  letter-spacing: 0.55px;
  color: var(--text) !important;
  border-bottom: 1px solid rgba(125,80,255,.18) !important;
  white-space: nowrap;
  text-align: left;
  vertical-align: middle;
}

table.table tbody td {
  padding: 10px 10px !important;
  font-size: 0.86rem !important;
  border-bottom: 1px solid var(--line) !important;
  color: var(--text) !important;
  vertical-align: middle;
  white-space: normal;
  word-break: break-word;
  overflow: visible;
}

table.table tbody tr:nth-child(even) {
  background: rgba(125,80,255,.04);
}

table.table tbody tr:hover {
  background: linear-gradient(135deg, rgba(125,80,255,.10), rgba(56,189,248,.08));
}

.status-ok { color: var(--success); font-weight: 900; }
.status-warn { color: var(--warning); font-weight: 900; }
.status-bad { color: var(--danger); font-weight: 900; }

/* ============================================================================
   8. AGREEMENT TABLE - SPECIFIC
   ============================================================================ */

.agreement-surface {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  box-shadow: var(--shadow);
}

.agreement-scroll {
  overflow-x: visible;
  -webkit-overflow-scrolling: touch;
  border-radius: 12px;
}

table.table.agreement-table {
  min-width: 0 !important;
  border: 1px solid rgba(37,99,235,.18);
}

table.table.agreement-table thead {
  background: linear-gradient(90deg,
    rgba(37,99,235,.28),
    rgba(56,189,248,.24),
    rgba(236,72,153,.16)
  );
}

table.table.agreement-table thead th {
  padding: 10px 10px !important;
  font-size: 0.78rem !important;
  color: #0f172a !important;
  border-bottom: 1px solid rgba(37,99,235,.18) !important;
  white-space: nowrap !important;
}

html[data-theme="dark"] table.table.agreement-table thead th {
  color: #ffffff !important;
  border-bottom: 1px solid rgba(56,189,248,.18) !important;
}

table.table.agreement-table tbody td {
  padding: 10px 10px !important;
  font-size: 0.86rem !important;
  white-space: nowrap;
  word-break: normal;
  overflow: visible;
}

table.table.agreement-table tbody tr:nth-child(even) {
  background: rgba(37,99,235,.03);
}

table.table.agreement-table tbody tr:hover {
  background: linear-gradient(135deg, rgba(37,99,235,.12), rgba(56,189,248,.10));
}

html[data-theme="dark"] table.table.agreement-table tbody tr:nth-child(even) {
  background: rgba(255,255,255,.03);
}

html[data-theme="dark"] table.table.agreement-table tbody tr:hover {
  background: rgba(56,189,248,.12);
}

table.table.agreement-table th:last-child,
table.table.agreement-table td:last-child {
  width: 170px;
  text-align: center;
  white-space: nowrap;
}

table.table.agreement-table .actions {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}

/* Mobile */
@media (max-width: 820px) {
  .agreement-scroll { overflow-x: auto; }

  table.table.agreement-table,
  table.table {
    table-layout: auto;
    min-width: 900px;
  }
}

/* ============================================================================
   9. PAGINATION
   ============================================================================ */

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px 0;
}

.pager-btn {
  padding: 10px 18px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.pager-btn:hover:not(.disabled) {
  background: var(--accent-soft);
  border-color: var(--accent);
  transform: translateY(-1px);
}

.pager-btn.disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.pager-mid {
  padding: 0 12px;
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
}

/* Light mode specific */
html[data-theme="light"] .pager-btn {
  background: rgba(125,80,255,.08);
  border-color: rgba(125,80,255,.25);
}

html[data-theme="light"] .pager-btn:hover:not(.disabled) {
  background: rgba(125,80,255,.16);
  border-color: rgba(125,80,255,.45);
}

/* ============================================================================
   NOTE:
   If theme still "same", it's 99% browser cache.
   Add version: /css/style.css?v=3 and hard refresh (Ctrl+F5)
   ============================================================================ */
/* ===============================
   FIX TEXT BREAK IN AGREEMENT TABLE
   =============================== */

.agreement-table th,
.agreement-table td {
    white-space: nowrap;
}

/* ===== Table Alignment ===== */
.col-no{ width:60px;text-align:center; }
.col-left{ text-align:left; }
.col-center{ text-align:center; }
.no-data{ text-align:center;padding:20px; }

.muted-row{
  opacity:0.6;
}

/* ===== Action Buttons ===== */
.actions-row{
  display:flex;
  gap:8px;
  align-items:center;
  justify-content:center;
}

/* Base Button */
.iconbtn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  width:36px;
  height:36px;
  border-radius:10px;
  border:1px solid var(--line);
  background:var(--panel);
  color:var(--text);
  transition:all .25s cubic-bezier(.4,0,.2,1);
  cursor:pointer;
}

/* Icon */
.iconbtn svg{
  width:18px;
  height:18px;
  fill:currentColor;
  transition:all .25s ease;
}

/* ✨ Hover Animation */
.iconbtn:hover{
  transform:translateY(-3px) scale(1.08);
  box-shadow:0 6px 14px rgba(125,80,255,.25);
  border-color:rgba(125,80,255,.6);
}

/* Icon bounce */
.iconbtn:hover svg{
  transform:scale(1.1) rotate(-5deg);
}

/* Active click effect */
.iconbtn:active{
  transform:scale(.95);
}

/* Delete Style */
.iconbtn.danger{
  border-color:rgba(239,68,68,.4);
}

.iconbtn.danger:hover{
  background:rgba(239,68,68,.12);
  color:#ef4444;
  box-shadow:0 6px 14px rgba(239,68,68,.3);
}

/* ===============================
   AGREEMENT ACTION SPECIAL EFFECT
   =============================== */

.agreement-actions .iconbtn{
  transition: all .35s cubic-bezier(.4,0,.2,1);
}

/* Lift + Glow */
.agreement-actions .iconbtn:hover{
  transform: translateY(-6px) scale(1.15);
  box-shadow: 0 12px 25px rgba(37,99,235,.35);
  border-color: var(--accent);
}

/* Icon animation */
.agreement-actions .iconbtn:hover svg{
  transform: rotate(-18deg) scale(1.2);
  transition: all .35s ease;
}

/* Click press */
.agreement-actions .iconbtn:active{
  transform: scale(.92);
}

/* Renew glow */
.agreement-actions .action-renew:hover{
  background: rgba(56,189,248,.18);
  color: #38bdf8;
  box-shadow: 0 12px 28px rgba(56,189,248,.45);
}

/* Delete glow */
.agreement-actions .action-delete:hover{
  background: rgba(239,68,68,.18);
  color: #ef4444;
  box-shadow: 0 12px 28px rgba(239,68,68,.55);
}

/* =========================================
   RENEW MODAL SUPPORT DARK + LIGHT
========================================= */

.renew-overlay{
  display:none;
  position:fixed;
  inset:0;
  background:rgba(0,0,0,.55);
  z-index:99999;
}

.renew-overlay.active{
  display:flex !important;
  justify-content:center;
  align-items:center;
}

.renew-card{
  background:var(--panel);
  border:1px solid var(--line);
  padding:25px;
  border-radius:16px;
  width:380px;
  color:var(--text);
  box-shadow:var(--shadow);
}