:root {
  --primary: #505530;
  --accent: #E2AE2B;
  --ochre: #A68032;
  --bg: #F5F6F5;
  --surface: #FFFFFF;
  --sage: #A5A88B;
  --text: #2B2D24;
  --muted: #6B6E5F;
  --line: #E1E3DA;
  --danger: #B42318;
  --ok: #2F7D32;
  --radius: 10px;
  font-family: "Segoe UI", Inter, system-ui, -apple-system, Arial, sans-serif;
  font-size: 13.5px;
  color: var(--text);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; overflow-x: hidden; }
h1 { font-size: 19px; margin: 0 0 2px; color: var(--primary); }
h2 { font-size: 15px; margin: 0 0 10px; color: var(--primary); }
p { margin: 0 0 6px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); font-size: 12.5px; min-height: 1em; margin: 3px 0; }

.topbar { display: flex; align-items: center; justify-content: space-between; background: var(--primary); color: #fff; padding: 7px 16px; position: sticky; top: 0; z-index: 5; flex-wrap: wrap; gap: 8px; }
.topbar-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.topbar-actions .btn { padding: 5px 10px; font-size: 12px; }
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand-name { font-weight: 800; font-size: 16px; }
.brand-sub { color: var(--accent); font-size: 11.5px; font-weight: 600; }

.layout { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: calc(100vh - 46px); max-width: 100vw; overflow-x: hidden; }
.sidebar { background: var(--surface); border-right: 1px solid var(--line); padding: 12px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.main { padding: 12px 18px 28px; width: 100%; max-width: 100%; min-width: 0; box-sizing: border-box; }

.matter-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.matter-list li button { width: 100%; text-align: left; background: none; border: 1px solid transparent; border-radius: 8px; padding: 7px 9px; cursor: pointer; font: inherit; color: inherit; }
.matter-list li button:hover { background: var(--bg); }
.matter-list li button.active { background: #F7EFD6; border-color: var(--accent); }
.matter-list .ml-name { font-weight: 700; font-size: 13.5px; display: block; }
.matter-list .ml-meta { font-size: 11.5px; color: var(--muted); display: block; }
.matter-list .empty { color: var(--muted); font-size: 12.5px; padding: 6px; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 10px; }
details.panel > summary { cursor: pointer; font-weight: 700; color: var(--primary); font-size: 14px; }
details.panel[open] > summary { margin-bottom: 10px; }
.welcome .steps li { margin-bottom: 5px; }

.matter-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px 12px; margin-bottom: 8px; }
.matter-head-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; max-width: 100%; }
.report-bar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }

.cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-bottom: 10px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; }
.card .label { font-size: 11.5px; color: var(--muted); font-weight: 600; line-height: 1.25; }
.card .value { font-size: 17px; font-weight: 800; color: var(--primary); margin-top: 1px; }
.card.highlight { border-color: var(--accent); background: #FBF5E3; }

.grid-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 12px; }
.grid-form .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 3px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.field .hint { font-weight: 400; font-size: 11.5px; }
.input { font: inherit; font-size: 13.5px; color: var(--text); background: #fff; border: 1px solid #CDD0C3; border-radius: 7px; padding: 6px 9px; width: 100%; }
.input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
textarea.input { resize: vertical; }
.input.money { text-align: right; }
.check { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--text); font-weight: 500; }

.btn { font: inherit; font-size: 13px; font-weight: 700; border-radius: 8px; padding: 6px 12px; border: 1px solid transparent; cursor: pointer; white-space: nowrap; }
.btn.primary { background: var(--accent); color: var(--primary); }
.btn.primary:hover { background: var(--ochre); color: #fff; }
.btn.secondary { background: var(--primary); color: #fff; }
.btn.secondary:hover { background: #3d4124; }
.btn.ghost { background: transparent; border-color: #CDD0C3; color: var(--text); }
.btn.ghost:hover { background: var(--bg); }
.btn.ghost.light { color: #fff; border-color: rgba(255, 255, 255, .5); }
.btn.ghost.light:hover { background: rgba(255, 255, 255, .12); }
.btn.danger { background: transparent; border-color: #E8B4AF; color: var(--danger); }
.btn.danger:hover { background: #FBE4E1; }
.btn.small { font-size: 12px; padding: 4px 8px; border-radius: 6px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.actions .spacer { flex: 1; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin: -4px -4px 14px; padding-bottom: 10px; }
.tab { font: inherit; font-size: 14px; font-weight: 700; padding: 8px 12px; border-radius: 9px; border: 1px solid var(--line); background: var(--bg); color: var(--muted); cursor: pointer; transition: all .15s ease; }
.tab .num { display: inline-block; width: 20px; height: 20px; line-height: 20px; text-align: center; border-radius: 50%; background: var(--line); color: var(--primary); font-size: 12px; margin-right: 6px; }
.tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.tab.active .num { background: var(--accent); color: var(--primary); font-weight: 800; }
.tab.done { border-color: #86efac; background: #f0fdf4; color: #166534; }
.tab.done .num { background: #16a34a; color: #fff; }
.tab.done.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.tab.done.active .num { background: #16a34a; color: #fff; }
.tab-check { color: #16a34a; font-weight: 800; margin-left: 4px; }
.tab.active .tab-check { color: #86efac; }
.tab-intro { font-size: 13.5px; color: var(--muted); margin-bottom: 12px; }

.guide-banner { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; padding: 12px 16px; border-radius: 10px; margin-bottom: 14px; }
.guide-banner-text { flex: 1 1 300px; min-width: 0; }
.guide-banner-title { font-size: 13.5px; font-weight: 800; }
.guide-banner-sub { font-size: 12px; margin-top: 2px; line-height: 1.4; }
.guide-banner-action { flex: 0 0 auto; }
.guide-banner.pending { background: #fefce8; border: 1.5px solid #facc15; }
.guide-banner.pending .guide-banner-title { color: #854d0e; }
.guide-banner.pending .guide-banner-sub { color: #713f12; }
.guide-banner.next { background: #eff6ff; border: 1.5px solid #60a5fa; }
.guide-banner.next .guide-banner-title { color: #1e40af; }
.guide-banner.next .guide-banner-sub { color: #1e3a8a; }
.guide-banner.waiting { background: #fffbeb; border: 1.5px solid #f59e0b; }
.guide-banner.waiting .guide-banner-title { color: #b45309; }
.guide-banner.waiting .guide-banner-sub { color: #92400e; }
.guide-banner.progress { background: #f0fdf4; border: 1.5px solid #4ade80; }
.guide-banner.progress .guide-banner-title { color: #15803d; }
.guide-banner.progress .guide-banner-sub { color: #166534; }
.guide-banner.complete { background: #ecfdf5; border: 1.5px solid #10b981; }
.guide-banner.complete .guide-banner-title { color: #047857; }
.guide-banner.complete .guide-banner-sub { color: #065f46; }

.lines { width: 100%; border-collapse: collapse; margin: 8px 0; }
.lines th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 700; padding: 4px 6px; border-bottom: 1px solid var(--line); }
.lines td { padding: 4px 4px; vertical-align: top; }
.lines .col-amount { width: 130px; }
.lines .col-kind { width: 150px; }
.lines .col-date { width: 150px; }
.lines .col-basis { width: 130px; }
.lines .col-gst { width: 80px; text-align: center; }
.lines .col-x { width: 36px; }

.calc { display: flex; flex-wrap: wrap; gap: 6px 18px; justify-content: flex-end; background: var(--bg); border-radius: 10px; padding: 10px 14px; font-size: 14px; }
.calc strong { color: var(--primary); }
.calc .err { color: var(--danger); }

.notice { border-radius: 10px; padding: 10px 14px; font-size: 13.5px; margin-bottom: 12px; border: 1px solid; }
.notice.warn { background: #FFF8E6; border-color: #F0D58A; color: #6B4E00; }
.notice.info { background: #F0F4EA; border-color: #CBD5B8; color: #3D4524; }
.notice ul { margin: 6px 0 0; padding-left: 18px; }
.convert-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; background: #FBF5E3; border: 1px solid var(--accent); border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; font-size: 13.5px; }
.convert-bar .convert-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.edit-banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: #FFF8E6; border: 1px solid var(--accent); border-radius: 10px; padding: 9px 14px; margin-bottom: 12px; font-size: 13.5px; font-weight: 600; color: var(--primary); }

.table-wrap { width: 100%; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: 10px; background: #fff; margin-bottom: 18px; }
.doc-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.doc-table th { text-align: left; font-size: 12px; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); background: #FAFBF9; white-space: nowrap; }
.doc-table td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; word-break: break-word; }
.doc-table td.num { text-align: right; white-space: nowrap; }
.doc-table tr.void td { color: var(--muted); text-decoration: line-through; }
.doc-table tr.void td.keep { text-decoration: none; }
.doc-table .row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.badge { display: inline-block; font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--line); color: var(--primary); white-space: nowrap; }
.badge.ok { background: #E3F1E4; color: var(--ok); }
.badge.void { background: #FBE4E1; color: var(--danger); }
.badge.due { background: #FBF0D2; color: #7A5A00; }

.settings dl { display: grid; grid-template-columns: 220px 1fr; gap: 6px 12px; font-size: 14px; margin: 0 0 16px; }
.settings dt { color: var(--muted); font-weight: 600; }
.settings dd { margin: 0; }

.dialog { border: none; border-radius: 14px; padding: 20px 22px; width: min(560px, 94vw); box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.dialog::backdrop { background: rgba(30, 32, 20, .45); }
.dialog .field { margin-bottom: 10px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%) translateY(120%); background: var(--primary); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; transition: transform .2s; max-width: 90vw; z-index: 50; }
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); }

.folder-picker-row { display: flex; gap: 8px; align-items: stretch; }
.folder-picker-row .input { flex: 1; font-family: Consolas, monospace; font-size: 13px; }
.immi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 8px 12px; margin-bottom: 16px; width: 100%; }
.immi-kv { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 13px; min-width: 0; box-sizing: border-box; }
.immi-kv .k { color: var(--muted); font-weight: 600; font-size: 12px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.immi-kv .v { color: var(--text); font-weight: 700; font-size: 13px; word-break: break-word; }
.immi-kv input.small-input { border: 1px solid #C4C8B8; border-radius: 6px; background: #fff; width: 100%; box-sizing: border-box; }
.copy-btn { font: inherit; font-size: 11.5px; font-weight: 700; padding: 3px 8px; border-radius: 6px; border: 1px solid #CDD0C3; background: #fff; color: var(--primary); cursor: pointer; flex-shrink: 0; }
.copy-btn:hover { background: var(--accent); border-color: var(--accent); }
.audit-item { border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; margin-bottom: 8px; background: #fff; }
.audit-item.crit { border-color: #E8B4AF; background: #FFF5F4; }
.audit-item.warn { border-color: #F0D58A; background: #FFFDF5; }
.audit-item.pass { border-color: #C5DEC6; background: #F6FBF6; }

/* Renamed Files Table: High-density, fits window cleanly without overflow */
.files-table { width: 100%; border-collapse: collapse; font-size: 13px; table-layout: fixed; }
.files-table th { background: #F6F7F3; color: var(--text); font-weight: 700; font-size: 12px; padding: 10px 12px; border-bottom: 2px solid var(--line); vertical-align: bottom; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; box-sizing: border-box; }
.files-table td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top !important; box-sizing: border-box; }
.files-table tr:hover td { background: #FAFBF8; }

.files-table td.col-orig { font-size: 11.5px; color: var(--muted); word-break: break-word; overflow-wrap: anywhere; line-height: 1.35; }

.files-table td.col-clean { line-height: 1.35; }
.clean-name-box { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.clean-name-box strong { font-size: 12.5px; color: #2B3014; word-break: break-word; overflow-wrap: anywhere; }

.files-table td.col-person { font-size: 12.5px; line-height: 1.35; font-weight: 600; color: var(--text); word-break: break-word; overflow-wrap: anywhere; }
.files-table td.col-person .dob-badge { display: block; font-size: 11.5px; font-weight: 500; color: var(--muted); margin-top: 3px; }

.files-table td.col-dates { font-size: 12px; white-space: nowrap; line-height: 1.45; color: var(--text); }
.files-table td.col-dates .date-line { display: block; white-space: nowrap; }
.files-table td.col-dates .date-line strong { color: #8F3B34; }

.files-table td.col-summary { font-size: 12.5px; color: #2D311E; line-height: 1.45; word-break: break-word; overflow-wrap: anywhere; }

@media (max-width: 1200px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--line); }
  .matter-list { max-height: 220px; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-form, .immi-grid { grid-template-columns: 1fr; }
  .main { padding: 10px; }
}

/* Microsoft 365 & OneDrive 1-Click UI */
.btn-ms-login {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: #ffffff;
  color: #5E5E5E;
  border: 1px solid #8C8C8C;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 13.5px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.btn-ms-login:hover {
  background: #fbfbfb;
  border-color: #666666;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  color: #262626;
}
.btn-ms-login:active {
  background: #f0f0f0;
}
.btn-ms-login svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}
.m365-card {
  border-radius: 10px;
  padding: 18px 20px;
  margin: 14px 0 24px 0;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  border: 1px solid #E5E7EB;
  background: #ffffff;
}
.m365-card.connected {
  border-left: 4px solid #10B981;
  background: #F0FDF4;
}
.m365-card.disconnected {
  border-left: 4px solid #3B82F6;
  background: #F8FAFC;
}

