/* ===== INV Global Styles ===== */
:root {
  --navy: #1a1a2e;
  --navy-light: #2a2a4e;
  --blue: #4361ee;
  --blue-hover: #3451d1;
  --white: #ffffff;
  --bg: #f4f6fb;
  --card-bg: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --success: #16a34a;
  --success-bg: #dcfce7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --warning: #d97706;
  --warning-bg: #fef3c7;
  --sidebar-w: 240px;
  --topbar-h: 60px;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.04);
}

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

body {
  margin: 0;
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Auth Pages ===== */
.auth-body {
  background: linear-gradient(135deg, var(--navy) 0%, #16213e 100%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-container {
  background: var(--white);
  border-radius: 16px;
  padding: 48px 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}

.auth-logo {
  text-align: center;
  display: flex;
  justify-content: center;
  margin-bottom: 32px;
}

.brand-logo {
  display: block;
}

.brand-logo-auth {
  width: min(180px, 100%);
  height: auto;
}

.auth-form { margin-bottom: 20px; }

.auth-link {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  margin: 0;
}

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

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--navy);
  color: var(--white);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform .25s ease;
}

.sidebar-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.sidebar-logo {
  display: inline-flex;
  align-items: center;
  line-height: 0;
  text-decoration: none;
}

.brand-logo-sidebar {
  width: 80px;
  height: auto;
}

.sidebar-close {
  display: none;
  background: none;
  border: none;
  color: rgba(255,255,255,.6);
  cursor: pointer;
  font-size: 18px;
  padding: 4px;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 0;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 20px;
  color: rgba(255,255,255,.7);
  text-decoration: none;
  transition: background .15s, color .15s;
  border-radius: 0;
  font-size: 14px;
}

.nav-item:hover {
  background: rgba(255,255,255,.08);
  color: var(--white);
  text-decoration: none;
}

.nav-item.active {
  background: var(--blue);
  color: var(--white);
}

.nav-icon { font-size: 16px; min-width: 20px; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,.08);
}

.btn-logout {
  background: none;
  border: 1px solid rgba(255,255,255,.2);
  color: rgba(255,255,255,.6);
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  width: 100%;
  transition: all .15s;
}

.btn-logout:hover {
  border-color: rgba(255,255,255,.5);
  color: var(--white);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 99;
}

/* Main wrapper */
.main-wrapper {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: var(--topbar-h);
  background: var(--white);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.hamburger {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
}

.hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
}

.page-title {
  font-size: 17px;
  font-weight: 700;
  margin: 0;
  color: var(--text);
}

.main-content {
  padding: 28px 28px;
  flex: 1;
}

/* ===== Cards ===== */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 24px;
  margin-bottom: 20px;
  overflow: visible;
}

.card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 16px;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 7px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all .15s;
  text-decoration: none;
  line-height: 1;
}

.btn-primary {
  background: var(--blue);
  color: var(--white);
}
.btn-primary:hover {
  background: var(--blue-hover);
  color: var(--white);
  text-decoration: none;
}

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  background: var(--border);
  text-decoration: none;
}

.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #fca5a5;
}
.btn-danger:hover {
  background: #fecaca;
  text-decoration: none;
}

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

.btn-block { width: 100%; justify-content: center; }

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

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
}

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

label .hint {
  font-weight: 400;
  color: var(--text-muted);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="tel"],
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--white);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(67,97,238,.12);
}

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

/* ===== Alerts ===== */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 13px;
}

.alert-error {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #fca5a5;
}
.alert-error p { margin: 0 0 4px; }
.alert-error p:last-child { margin: 0; }

.alert-success {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid #86efac;
}

.alert-warning {
  background: var(--warning-bg);
  color: var(--warning);
  border: 1px solid #fcd34d;
}

/* ===== Badges ===== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .3px;
}

.badge-gray { background: #f1f5f9; color: #64748b; }
.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-green { background: var(--success-bg); color: var(--success); }

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; overflow-y: visible; }
.table-wrap table { overflow: visible; }
.documents-list-card {
  min-height: 360px;
}

.documents-list-wrap {
  min-height: 260px;
}

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

th {
  text-align: left;
  padding: 10px 14px;
  background: #f8fafc;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 11px 14px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
  min-height: 52px;
}

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

tbody tr:hover { background: #fafbff; }

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

/* ===== Page Header ===== */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

/* ===== Tabs ===== */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
}

.tab-link {
  padding: 8px 18px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  text-decoration: none;
  transition: color .15s;
}

.tab-link:hover { color: var(--blue); text-decoration: none; }
.tab-link.active { color: var(--blue); border-bottom-color: var(--blue); }

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

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

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: .3px;
  margin-bottom: 6px;
}

.stat-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--navy);
}

.stat-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ===== Document Edit — Line items ===== */
.lines-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.lines-table th {
  background: #f8fafc;
  padding: 8px 10px;
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
}

.lines-table td {
  padding: 6px 4px;
  vertical-align: middle;
  border-bottom: 1px solid #f1f5f9;
}

.lines-table input[type="text"],
.lines-table input[type="number"],
.lines-table select {
  padding: 7px 8px;
  font-size: 13px;
}

.lines-table .col-item { width: 30%; }
.lines-table .col-desc { width: 18%; }
.lines-table .col-qty  { width: 7%; }
.lines-table .col-unit { width: 6%; }
.lines-table .col-price{ width: 12%; }
.lines-table .col-tax  { width: 8%; }
.lines-table .col-amt  { width: 12%; text-align: right; }
.lines-table .col-del  { width: 5%; text-align: center; }

.btn-del-line {
  background: none;
  border: none;
  color: #ef4444;
  cursor: pointer;
  font-size: 16px;
  padding: 4px;
  line-height: 1;
}

.btn-del-line:hover { color: #b91c1c; }

/* Totals area */
.totals-area {
  display: flex;
  justify-content: flex-end;
  margin-top: 16px;
}

.totals-table {
  min-width: 260px;
  font-size: 13px;
}

.totals-table td { padding: 5px 0; }
.totals-table .total-row td {
  font-weight: 700;
  font-size: 16px;
  color: var(--navy);
  border-top: 2px solid var(--border);
  padding-top: 10px;
}
.totals-table td:first-child { color: var(--text-muted); }
.totals-table td:last-child { text-align: right; padding-left: 32px; }

/* Tax mode toggle */
.toggle-group {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 7px;
  overflow: hidden;
  display: inline-flex;
}

.toggle-btn {
  padding: 7px 16px;
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  background: var(--white);
  border: none;
  color: var(--text-muted);
  transition: all .15s;
}

.toggle-btn.active {
  background: var(--blue);
  color: var(--white);
}

/* Print */
@media print {
  .sidebar, .topbar, .page-header .btn, .doc-actions { display: none !important; }
  .main-wrapper { margin-left: 0 !important; }
  body { background: white; }
}

/* ===== Upload preview ===== */
.img-preview {
  width: 120px;
  height: 120px;
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  background: var(--bg);
  display: block;
  margin-bottom: 8px;
}

/* ===== Reports ===== */
.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 200px;
  padding: 0 8px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 8px;
}

.bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
}

.bar {
  width: 100%;
  background: var(--blue);
  border-radius: 4px 4px 0 0;
  min-height: 2px;
  transition: height .3s;
}

.bar-label { font-size: 10px; color: var(--text-muted); }
.bar-amount { font-size: 11px; color: var(--text); font-weight: 600; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-close { display: block; }
  .sidebar-overlay.open { display: block; }
  .main-wrapper { margin-left: 0; }
  .hamburger { display: flex; }
  .main-content { padding: 16px; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .auth-container { padding: 32px 24px; margin: 16px; }
  .brand-logo-auth { width: min(150px, 100%); }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}
