/* ===========================================================================
   KManage design system - shared across all pages
   =========================================================================== */

:root {
  --bg: #f2f4f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #dde3ec;
  --text: #1a2332;
  --text-muted: #5c6b80;
  --primary: #1f4e79;
  --primary-hover: #2a6399;
  --primary-soft: #e8f0f8;
  --success: #1e7e46;
  --success-soft: #e6f4ec;
  --danger: #b3372f;
  --danger-soft: #fbeae9;
  --warning: #9a6700;
  --warning-soft: #fff4d6;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(16, 30, 54, 0.08), 0 1px 2px rgba(16, 30, 54, 0.04);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}

/* --- top navigation (injected by app.js) --------------------------------- */

.km-nav {
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}
.km-nav-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  min-height: 52px;
}
.km-brand {
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  text-decoration: none;
  margin-right: 14px;
  letter-spacing: 0.3px;
  white-space: nowrap;
}
.km-brand span { color: #9fc3e8; }
.km-nav a.km-link {
  color: rgba(255, 255, 255, 0.85);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 13.5px;
  white-space: nowrap;
}
.km-nav a.km-link:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }
.km-nav a.km-link.active { background: rgba(255, 255, 255, 0.18); color: #fff; font-weight: 600; }
.km-nav-spacer { flex: 1; }
.km-user {
  color: rgba(255, 255, 255, 0.9);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}
.km-user .km-tenant { opacity: 0.75; }
.km-logout {
  background: rgba(255, 255, 255, 0.14);
  border: none;
  color: #fff;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.km-logout:hover { background: rgba(255, 255, 255, 0.25); }

/* --- main content wrapper -------------------------------------------------- */

.km-main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

h1 { font-size: 24px; font-weight: 700; margin: 4px 0 18px; }
h2 { font-size: 18px; font-weight: 650; margin: 0 0 12px; }
h3 { font-size: 15.5px; font-weight: 650; margin: 16px 0 8px; }
h4 { font-size: 14px; font-weight: 650; margin: 12px 0 6px; }

hr { border: none; border-top: 1px solid var(--border); margin: 24px 0; }

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

/* --- cards / sections ------------------------------------------------------ */

.container { max-width: 1280px; margin: 0 auto; }

.section, form, .card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin: 0 0 20px;
  box-shadow: var(--shadow);
}
.section h2:first-child, form h2:first-child, .card h2:first-child { margin-top: 0; }

/* nested sections shouldn't double-card */
.section .section, form .section, .section form { box-shadow: none; background: var(--surface-2); }

/* --- forms ------------------------------------------------------------------ */

/* legacy pages separate fields with <br><br>; the block layout below replaces them */
form br { display: none; }

label {
  display: block;
  font-weight: 600;
  font-size: 13px;
  color: var(--text-muted);
  margin: 14px 0 4px;
}
label:first-of-type { margin-top: 0; }

input, select, textarea {
  display: block;
  width: 100%;
  max-width: 520px;
  padding: 8px 12px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin: 2px 0 4px;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
input[type="checkbox"], input[type="radio"] {
  display: inline-block;
  width: auto;
  margin: 0 6px 0 0;
  vertical-align: middle;
}
textarea { min-height: 80px; resize: vertical; }

.form-group { margin: 0 0 4px; }
.form-group label { margin-top: 14px; }

fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin: 0 0 16px;
}
legend { font-weight: 650; font-size: 13.5px; padding: 0 6px; }

/* --- buttons ----------------------------------------------------------------- */

button, .btn, input[type="submit"] {
  display: inline-block;
  width: auto;
  background: var(--primary);
  color: #fff;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 13.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  margin: 10px 6px 2px 0;
  text-decoration: none;
  transition: background 0.12s ease;
}
button:hover, .btn:hover, input[type="submit"]:hover { background: var(--primary-hover); }
button:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-secondary, button.btn-secondary {
  background: var(--surface);
  color: var(--primary);
  border-color: var(--border);
}
.btn-secondary:hover, button.btn-secondary:hover { background: var(--primary-soft); }

.btn-success, button.btn-success { background: var(--success); }
.btn-success:hover, button.btn-success:hover { background: #24984f; }

.btn-danger, button.btn-danger { background: var(--danger); }
.btn-danger:hover, button.btn-danger:hover { background: #cf4a41; }

/* small inline buttons inside tables/lists */
td button, li button { padding: 4px 10px; font-size: 12.5px; margin: 2px 4px 2px 0; }

/* --- tables ------------------------------------------------------------------- */

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin: 12px 0 20px;
  font-size: 14px;
}
th, td {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
}
th {
  background: var(--surface-2);
  font-size: 12.5px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
}
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--primary-soft); }

/* --- lists -------------------------------------------------------------------- */

ul { padding-left: 20px; }
li { margin: 4px 0; }

/* --- dashboard nav grid --------------------------------------------------------- */

.nav-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
  margin: 20px 0;
}
.nav-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  text-align: center;
  box-shadow: var(--shadow);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}
.nav-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(16, 30, 54, 0.12);
  border-color: var(--primary);
}
.nav-card a { text-decoration: none; color: var(--text); display: block; }
.nav-card h3 { margin: 0 0 6px; color: var(--primary); }
.nav-card p { margin: 0; font-size: 13px; color: var(--text-muted); }

/* --- status / result boxes ------------------------------------------------------- */

.result-display, .status, .total-display, .split-total {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 14px;
  margin: 12px 0;
  font-size: 14px;
}
.success, .test-success { color: var(--success); }
.error, .test-error { color: var(--danger); }

.badge {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 650;
  padding: 2px 9px;
  border-radius: 20px;
  vertical-align: middle;
}
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-muted { background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }

/* --- page-specific helpers kept from the old inline styles ------------------------ */

.hidden { display: none !important; }

.split-container, .split-input, .shareholder-item, .entity-requirements {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px;
  margin: 10px 0;
}
.percentage-input, .splitAmount { max-width: 130px; display: inline-block; }
.side-by-side { display: flex; gap: 20px; flex-wrap: wrap; }
.side-by-side > * { flex: 1; min-width: 300px; }

.rule-builder { margin: 10px 0; }
.rule-node {
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  background: var(--surface-2);
  border-radius: 6px;
  padding: 10px 14px;
  margin: 8px 0;
}
.rule-node.fee { border-left-color: var(--success); }
.rule-node.if { border-left-color: var(--warning); }
.rule-node.split { border-left-color: var(--primary); }
.rule-name { font-weight: 650; }

/* --- login page -------------------------------------------------------------------- */

.km-login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.km-login {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 34px 32px;
  box-shadow: 0 8px 30px rgba(16, 30, 54, 0.12);
}
.km-login h1 { text-align: center; margin-bottom: 4px; }
.km-login .km-sub { text-align: center; color: var(--text-muted); font-size: 13.5px; margin: 0 0 22px; }
.km-login button { width: 100%; margin-top: 18px; padding: 10px; }
.km-login input { max-width: none; }

/* --- responsive --------------------------------------------------------------------- */

@media (max-width: 720px) {
  .km-main { padding: 16px 12px 40px; }
  input, select, textarea { max-width: none; }
  table { display: block; overflow-x: auto; }
}
