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

/* ── Palette ──────────────────────────────────────────────────────────────
   #fcf9ed  cream  – box background, surface
   #ebff99  lime   – accents, active, highlights
   #00ff00  green  – success
   #fb3900  red    – error, urgent, destructive
   #072122  dark   – body bg, navbar, headings, buttons
  ──────────────────────────────────────────────────────────────────────── */
:root {
  --cream:        #fcf9ed;
  --lime:         #ebff99;
  --green:        #00ff00;
  --red:          #fb3900;
  --dark:         #072122;

  --surface:      #ffffff;
  --surface-2:    #f5f2e7;
  --border:       rgba(7,33,34,.14);
  --border-strong:rgba(7,33,34,.28);
  --text:         #072122;
  --text-2:       #1a3a3c;
  --muted:        rgba(7,33,34,.5);

  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 14px;
  --shadow-xs: 0 1px 3px rgba(7,33,34,.08);
  --shadow-sm: 0 2px 8px rgba(7,33,34,.12), 0 1px 2px rgba(7,33,34,.06);
  --shadow:    0 8px 32px rgba(7,33,34,.18), 0 2px 8px rgba(7,33,34,.10);
  --shadow-box:0 20px 60px rgba(7,33,34,.35), 0 4px 16px rgba(7,33,34,.20);
  --t: 140ms ease;
}

/* ── Base ── */
html { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--dark);
  background-image: radial-gradient(circle, rgba(235,255,153,.10) 1px, transparent 1px);
  background-size: 22px 22px;
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100%;
  padding: 32px 16px 48px;
}

a { color: inherit; text-decoration: none; }

/* ── App Box ── */
.app-box {
  max-width: 1160px;
  margin: 0 auto;
  background: var(--cream);
  border-radius: 20px;
  box-shadow: var(--shadow-box);
  overflow: hidden;
  min-height: calc(100vh - 80px);
}

/* ── Navbar ── */
.navbar {
  background: var(--dark);
  padding: 0 28px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  height: 60px;
  gap: 16px;
}
.navbar-brand {
  display: flex;
  align-items: center;
  font-weight: 800;
  font-size: 16px;
  letter-spacing: -.3px;
  color: var(--cream);
  white-space: nowrap;
  flex-shrink: 0;
}
.navbar-brand span { color: var(--lime); }
.version-badge {
  font-size: 10px;
  font-weight: 700;
  color: rgba(235,255,153,.55);
  letter-spacing: .4px;
  border: 1px solid rgba(235,255,153,.2);
  border-radius: 99px;
  padding: 2px 8px;
  justify-self: end;
  white-space: nowrap;
  font-family: "SF Mono","Fira Code","Consolas",monospace;
}
.navbar-links {
  display: flex;
  align-items: center;
  gap: 2px;
}
.nav-link {
  padding: 7px 15px;
  border-radius: 99px;
  color: rgba(252,249,237,.6);
  font-size: 13px;
  font-weight: 500;
  transition: background var(--t), color var(--t);
  white-space: nowrap;
}
.nav-link:hover { background: rgba(235,255,153,.12); color: var(--cream); }
.nav-link.active { background: var(--lime); color: var(--dark); font-weight: 700; }

/* ── Page Content ── */
.container { max-width: 100%; padding: 28px 32px 40px; }
.page-header { margin-bottom: 24px; }
.page-header h1 { font-size: 22px; font-weight: 800; letter-spacing: -.4px; color: var(--dark); }
.page-header p  { color: var(--muted); margin-top: 4px; font-size: 13px; }

/* ── Card ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

/* ── Toolbar ── */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 16px;
}

/* ── Select ── */
select {
  height: 36px;
  padding: 0 32px 0 12px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23072122' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E") no-repeat right 10px center;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  appearance: none;
  transition: border-color var(--t), box-shadow var(--t);
}
select:focus {
  outline: none;
  border-color: var(--dark);
  box-shadow: 0 0 0 3px rgba(7,33,34,.12);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 16px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--t), border-color var(--t), color var(--t), box-shadow var(--t);
  white-space: nowrap;
  user-select: none;
}
.btn:hover  { background: var(--surface-2); }
.btn:active { transform: scale(.98); }
.btn:focus-visible { outline: 2px solid var(--dark); outline-offset: 2px; }
.btn.active,
.btn-primary {
  background: var(--dark);
  border-color: var(--dark);
  color: var(--lime);
  box-shadow: 0 1px 4px rgba(7,33,34,.25);
}
.btn.active:hover,
.btn-primary:hover { background: #0d3436; border-color: #0d3436; }
.btn:disabled { opacity: .4; cursor: not-allowed; pointer-events: none; }

.btn-group { display: flex; }
.btn-group .btn { border-radius: 0; border-right-width: 0; }
.btn-group .btn:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.btn-group .btn:last-child  { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; border-right-width: 1.5px; }

.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text-2); border-color: var(--border); }

/* ── Digit filter ── */
.digit-filter { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 20px; }
.digit-btn {
  min-width: 46px;
  height: 32px;
  padding: 0 12px;
  border: 1.5px solid var(--border-strong);
  border-radius: 99px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--t);
}
.digit-btn:hover { border-color: var(--dark); color: var(--dark); background: var(--lime); }
.digit-btn.active { background: var(--dark); border-color: var(--dark); color: var(--lime); box-shadow: 0 1px 4px rgba(7,33,34,.25); }
.digit-btn:focus-visible { outline: 2px solid var(--dark); outline-offset: 2px; }

/* ── Loading / Spinner ── */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--dark);
  border-radius: 50%;
  animation: spin .65s linear infinite;
  flex-shrink: 0;
}
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 72px 0;
  color: var(--muted);
  font-size: 13px;
}

/* ── Tables ── */
.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  overflow-x: auto;
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead tr { background: var(--dark); }
th {
  padding: 10px 16px;
  font-weight: 700;
  color: var(--lime);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  text-align: left;
  white-space: nowrap;
  border-bottom: none;
}
td { padding: 10px 16px; border-top: 1px solid var(--border); color: var(--text-2); }
tbody tr { transition: background var(--t); }
tbody tr:hover td { background: #f0f8e8; }
.text-center { text-align: center; }
.font-mono { font-family: "SF Mono","Fira Code","Consolas",monospace; font-size: 12px; }
.font-bold  { font-weight: 600; color: var(--text); }
.empty-msg  { padding: 48px; text-align: center; color: var(--muted); font-size: 13px; }

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .3px;
  border: 1px solid transparent;
}
.badge-green  { background: rgba(0,255,0,.12); color: #1a7a00; border-color: rgba(0,255,0,.35); }
.badge-red    { background: rgba(251,57,0,.08); color: var(--red); border-color: rgba(251,57,0,.25); }
.badge-blue   { background: rgba(7,33,34,.07); color: var(--dark); border-color: var(--border-strong); }
.badge-yellow { background: rgba(235,255,153,.35); color: #5a6600; border-color: rgba(235,255,153,.8); }
.badge-gray   { background: var(--surface-2); color: var(--muted); border-color: var(--border); }

/* ── Alerts ── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 16px;
  border: 1px solid transparent;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.alert::before { font-size: 15px; flex-shrink: 0; line-height: 1.4; }
.alert-error   { background: rgba(251,57,0,.07); color: var(--red); border-color: rgba(251,57,0,.2); }
.alert-error::before { content: "✕"; }
.alert-success { background: rgba(0,255,0,.08); color: #1a7a00; border-color: rgba(0,255,0,.25); }
.alert-success::before { content: "✓"; }
.alert-info    { background: rgba(235,255,153,.25); color: var(--text-2); border-color: rgba(235,255,153,.7); }
.alert-info::before { content: "ℹ"; }

/* ── Input ── */
.input {
  height: 40px;
  padding: 0 14px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  width: 100%;
  transition: border-color var(--t), box-shadow var(--t);
}
.input:focus { outline: none; border-color: var(--dark); box-shadow: 0 0 0 3px rgba(7,33,34,.12); }
.input::placeholder { color: var(--muted); }
.input:focus-visible { outline: none; }
.input-row { display: flex; gap: 10px; margin-bottom: 20px; }
.input-row .input { flex: 1; }
.input-row .btn-primary { height: 40px; flex-shrink: 0; }

/* ── Tabs ── */
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  border: none;
  background: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  transition: color var(--t), border-color var(--t), background var(--t);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}
.tab:hover  { color: var(--text); background: var(--surface-2); }
.tab.active { color: var(--dark); border-bottom-color: var(--dark); font-weight: 700; }
.tab:focus-visible { outline: 2px solid var(--dark); outline-offset: 2px; }

/* ── Calendar ── */
.cal-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.cal-nav-title {
  font-weight: 700;
  font-size: 15px;
  min-width: 180px;
  text-align: center;
  color: var(--text);
}
.cal-grid-header {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  background: var(--dark);
  border-radius: var(--radius) var(--radius) 0 0;
  border: 1px solid var(--dark);
  border-bottom: none;
}
.cal-day-name {
  padding: 10px 6px;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: rgba(235,255,153,.7);
  text-transform: uppercase;
  letter-spacing: .3px;
}
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.cal-cell {
  min-height: 108px;
  padding: 8px;
  border-top: 1px solid var(--border);
  border-right: 1px solid var(--border);
  transition: background var(--t);
}
.cal-cell:nth-child(7n) { border-right: none; }
.cal-cell:not(.empty):hover { background: #f0f8e8; }
.cal-cell.empty { background: rgba(7,33,34,.025); opacity: .55; }
.cal-cell.today { background: rgba(235,255,153,.15); }
.cal-day-num { font-size: 18px; font-weight: 700; color: var(--text); margin-bottom: 4px; line-height: 1; }
.cal-cell.today .cal-day-num {
  background: var(--dark);
  color: var(--lime);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
}
.cal-badges { display: flex; flex-direction: column; gap: 3px; }
.cal-badge {
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 6px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.2;
}
.cal-badge.digit  { background: rgba(235,255,153,.45); color: var(--dark); }
.cal-badge.bc     { background: rgba(235,255,153,.8);  color: var(--dark); }
.cal-badge.urgent { background: rgba(251,57,0,.13);    color: var(--red); }
.cal-badge-digit  { font-size: 14px; font-weight: 800; }
.cal-badge-period { font-size: 10px; font-weight: 500; opacity: .65; }
.today-circle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--dark);
  color: var(--lime);
  font-size: 18px;
  font-weight: 800;
}

/* ── Period grid (year view) ── */
.period-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 16px;
}
.period-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-xs);
  transition: box-shadow var(--t), transform var(--t);
}
.period-card:hover { box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.period-card-header {
  background: var(--dark);
  padding: 13px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.period-name {
  font-size: 13px;
  font-weight: 800;
  color: var(--cream);
  letter-spacing: -.2px;
}
.period-due-label {
  font-size: 11px;
  color: rgba(235,255,153,.65);
}
.period-mini-cal { padding: 14px 14px 12px; }

/* ── Mini calendar (inside period cards) ── */
.mini-cal-month {
  font-size: 11px;
  font-weight: 700;
  color: var(--dark);
  text-transform: uppercase;
  letter-spacing: .4px;
  margin-bottom: 8px;
}
.mini-cal-head {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  margin-bottom: 3px;
}
.mini-cal-head > span {
  font-size: 9px;
  font-weight: 700;
  color: var(--muted);
  text-align: center;
  padding: 1px 0;
  text-transform: uppercase;
}
.mini-cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}
.mini-cal-cell {
  min-height: 34px;
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 2px 1px;
}
.mini-cal-cell.has-venc { background: var(--lime); }
.mini-cal-cell.mini-today { outline: 2px solid var(--dark); outline-offset: -2px; border-radius: 4px; }
.mini-day {
  font-size: 10px;
  font-weight: 500;
  color: var(--muted);
  line-height: 1.4;
}
.mini-cal-cell.has-venc .mini-day { color: var(--dark); font-weight: 800; }
.mini-badges {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1px;
  margin-top: 1px;
}
.mini-badge {
  font-size: 7px;
  font-weight: 800;
  background: var(--dark);
  color: var(--lime);
  border-radius: 3px;
  padding: 0 3px;
  line-height: 1.5;
  letter-spacing: 0;
}
.mini-cal-empty {
  color: var(--muted);
  font-size: 12px;
  padding: 10px 0;
  text-align: center;
}

/* ── Urgent table cell ── */
.urgent-cell { color: var(--red) !important; font-weight: 700; }

/* ── Calendar badge with period label ── */

/* ── RUC ── */
.info-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.info-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  transition: border-color var(--t);
}
.info-item:hover { border-color: var(--border-strong); }
.info-item label { display: block; font-size: 10px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 4px; }
.info-item span  { font-size: 13px; font-weight: 500; color: var(--text); word-break: break-word; }

.ruc-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  padding: 20px 24px;
  background: var(--dark);
  border-radius: var(--radius-lg);
  border: none;
}
.ruc-header h2  { font-size: 18px; font-weight: 800; letter-spacing: -.3px; color: var(--cream); }
.ruc-header p   { color: rgba(252,249,237,.55); font-size: 13px; margin-top: 4px; font-family: "SF Mono","Fira Code","Consolas",monospace; }
.ruc-badges     { display: flex; gap: 8px; flex-wrap: wrap; padding-top: 2px; }
.ruc-header .badge-green { background: rgba(0,255,0,.15); color: #5dff5d; border-color: rgba(0,255,0,.3); }
.ruc-header .badge-red   { background: rgba(251,57,0,.18); color: #ff7755; border-color: rgba(251,57,0,.3); }
.ruc-header .badge-gray  { background: rgba(252,249,237,.1); color: rgba(252,249,237,.6); border-color: rgba(252,249,237,.15); }

/* ── Urgent ── */
tr.urgent td { background: rgba(251,57,0,.05); }
tr.urgent:hover td { background: rgba(251,57,0,.09); }

/* ── JSON ── */
.json-view {
  background: var(--dark);
  color: rgba(235,255,153,.8);
  padding: 20px;
  border-radius: var(--radius);
  overflow-x: auto;
  font-size: 12px;
  font-family: "SF Mono","Fira Code","Consolas",monospace;
  line-height: 1.75;
  border: 1px solid rgba(235,255,153,.15);
}

/* ── Divider ── */
.divider { height: 1px; background: var(--border); margin: 20px 0; }

/* ── Responsive ── */
@media (max-width: 900px) {
  body { padding: 0; background-image: none; }
  .app-box { border-radius: 0; box-shadow: none; min-height: 100vh; }
}
@media (max-width: 768px) {
  .container { padding: 20px 20px; }
  .navbar { padding: 0 20px; }
  .navbar-links { flex-wrap: wrap; }
  .period-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
  .navbar { grid-template-columns: 1fr; height: auto; padding: 12px 16px; gap: 8px; }
  .navbar-brand { justify-self: center; }
  .navbar-links { justify-self: center; }
  .version-badge { justify-self: center; }
}
@media (max-width: 480px) {
  .container { padding: 16px 14px; }
  .input-row { flex-direction: column; }
  .input-row .btn-primary { width: 100%; }
  .page-header h1 { font-size: 19px; }
  .period-grid { grid-template-columns: 1fr; }
  .info-grid { grid-template-columns: 1fr; }
  .cal-cell { min-height: 60px; }
}

/* ── Print ── */
@media print {
  body { background: #fff; font-size: 12px; padding: 0; background-image: none; }
  .app-box { box-shadow: none; border-radius: 0; }
  .navbar, .toolbar, .digit-filter, .tabs, .btn-print, .cal-nav, .input-row { display: none !important; }
  .container { max-width: 100%; padding: 0; }
  -webkit-print-color-adjust: exact; print-color-adjust: exact;
  .table-wrap { border: 1px solid #ccc; box-shadow: none; border-radius: 0; overflow: visible; }
  table { font-size: 11px; }
  th, td { padding: 5px 10px; }
  thead tr { background: #1a3a3c !important; }
  th { color: #ebff99 !important; }
  tbody tr:hover td { background: none !important; }
  tr.urgent td { background: #ffe0e0 !important; }
  .json-view { display: none; }
  .page-header { margin-bottom: 10px; }
  .page-header h1 { font-size: 16px; }
  .card, .month-card { box-shadow: none; }
  .ruc-header { background: #072122 !important; padding: 12px; border-radius: 8px; }
}
