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

:root {
  --black: #000;
  --white: #f9f6f1;
  --grey:  #f4f4f4;
  --mid:   #ccc;
  --text:  #111;
  --muted: #555;
  --link:  #0000cc;
  --sidebar-w: 180px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --black: #e0e0e0;
    --white: #181818;
    --grey:  #252525;
    --mid:   #444;
    --text:  #e0e0e0;
    --muted: #999;
    --link:  #7799ff;
  }
}

[data-theme="light"] {
  --black: #000;
  --white: #f9f6f1;
  --grey:  #f4f4f4;
  --mid:   #ccc;
  --text:  #111;
  --muted: #555;
  --link:  #0000cc;
}

[data-theme="dark"] {
  --black: #e0e0e0;
  --white: #181818;
  --grey:  #252525;
  --mid:   #444;
  --text:  #e0e0e0;
  --muted: #999;
  --link:  #7799ff;
}

body {
  font-family: system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--white);
  margin: 0;
  overflow-x: hidden;
}

/* Layout */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}
.layout > * { min-width: 0; }

/* Sidebar */
aside {
  border-right: 2px solid var(--black);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}
.brand {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-weight: 700;
  font-size: 1.1rem;
  text-decoration: none;
  color: var(--text);
}
.brand img { display: block; flex-shrink: 0; }

.sidebar-bottom { margin-top: auto; display: flex; flex-direction: column; gap: .4rem; }
.sidebar-bottom form { margin: 0; max-width: none; }
.btn-theme {
  background: none;
  border: 2px solid var(--mid);
  color: var(--text);
  cursor: pointer;
  font-size: 1.1rem;
  padding: .3rem .6rem;
  font-family: inherit;
  width: fit-content;
}
.btn-theme:hover { border-color: var(--black); }
.btn-logout {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: .85rem;
  font-family: inherit;
  padding: 0 .5rem;
  text-align: left;
}
.btn-logout:hover { color: var(--text); }
aside nav {
  display: flex;
  flex-direction: column;
  gap: .1rem;
}
aside nav a {
  display: block;
  padding: .3rem .5rem;
  text-decoration: none;
  color: var(--text);
  border: 2px solid transparent;
}
nav a:hover {
  border-color: var(--black);
}

/* Main */
main {
  padding: 1.5rem 2rem;
}

/* Page header */
.page-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  border-bottom: 1px solid var(--black);
  margin-bottom: 1.5rem;
  padding-bottom: .5rem;
}
.page-header h1 { margin: 0; font-size: 1.4rem; }

/* Buttons */
.btn, .btn-secondary, button[type=submit]:not(.btn-shift) {
  display: inline-block;
  width: fit-content;
  align-self: flex-start;
  padding: .3rem .8rem;
  border: 2px solid var(--black);
  font-size: .9rem;
  cursor: pointer;
  text-decoration: none;
  background: var(--white);
  color: var(--text);
  font-family: inherit;
  white-space: nowrap;
}
.btn { background: var(--black); color: var(--white); }
button[type=submit]:hover, .btn:hover { opacity: .85; }

/* Table */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: .95rem;
}
th {
  text-align: left;
  border-bottom: 2px solid var(--black);
  padding: .4rem .6rem;
  font-weight: 600;
}
td {
  padding: .4rem .6rem;
  border-bottom: 1px solid var(--mid);
}
tr:hover td { background: var(--grey); }
a { color: var(--link); }

/* Forms */
form { max-width: 580px; display: flex; flex-direction: column; gap: .8rem; }
label { display: flex; flex-direction: column; gap: .2rem; font-size: .9rem; font-weight: 500; }
input, textarea, select {
  border: 2px solid var(--black);
  padding: .4rem .5rem;
  font-size: .95rem;
  font-family: inherit;
  width: 100%;
  background: var(--white);
  color: var(--text);
}
input:focus, textarea:focus { outline: 3px solid var(--black); outline-offset: 1px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.form-actions { display: flex; gap: 1rem; align-items: center; margin-top: .5rem; }

/* Detail (dl) */
dl { display: grid; grid-template-columns: 140px 1fr; gap: .4rem 1rem; max-width: 580px; }
dt { font-weight: 600; color: var(--muted); font-size: .9rem; }
dd { margin: 0; }
.notes { white-space: pre-wrap; }

/* Record nav (prev/next/edit on show pages) */
.record-nav {
  margin-left: auto;
  display: flex;
  gap: .3rem;
  align-items: center;
  white-space: nowrap;
  flex-shrink: 0;
}
.btn-delete {
  display: inline-block;
  width: fit-content;
  align-self: flex-start;
  padding: .2rem .6rem;
  border: 2px solid #c00;
  text-decoration: none;
  color: #c00;
  font-size: .9rem;
  background: var(--white);
  cursor: pointer;
  font-family: inherit;
  line-height: 1.4;
  white-space: nowrap;
}
.btn-delete:hover { background: #c00; color: var(--white); }

.record-nav a, .record-nav .disabled {
  display: inline-block;
  padding: .2rem .6rem;
  border: 2px solid var(--black);
  text-decoration: none;
  color: var(--text);
  font-size: .9rem;
  line-height: 1.4;
}
.record-nav .disabled { color: var(--mid); border-color: var(--mid); cursor: default; }
.record-nav a:hover { background: var(--grey); }

/* Due date colors */
.due-overdue { color: #cc2200; }
.due-today   { color: #2a7a2a; }
[data-theme="dark"] .due-overdue { color: #ff6b6b; }
[data-theme="dark"] .due-today   { color: #66bb66; }

/* Action column */
.col-action { width: 2rem; text-align: center; }
.col-action a { text-decoration: none; font-size: 1.2rem; opacity: .8; }
.col-action a:hover { opacity: 1; }

/* Tabs */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--black);
  margin-top: 2rem;
}
.tab {
  padding: .4rem 1rem;
  text-decoration: none;
  color: var(--text);
  border: 2px solid transparent;
  border-bottom: none;
  margin-bottom: -2px;
  font-size: .9rem;
}
.tab:hover { background: var(--grey); }
.tab.active {
  border-color: var(--black);
  background: var(--white);
  font-weight: 600;
}
.tab-content { padding-top: 1rem; }
.tab-toolbar { margin-bottom: .8rem; }

/* Status badge */
.status { font-size: .8rem; font-weight: 600; padding: .1rem .4rem; border: 2px solid; }
.status-open { border-color: #aaa; color: var(--muted); }
.status-won  { border-color: #080; color: #080; }
.status-lost { border-color: #c00; color: #c00; }

/* Toggle done */
.col-toggle { white-space: nowrap; width: 1px; }
.col-toggle form { display: inline; }
.btn-toggle {
  display: inline-block;
  padding: .3rem .8rem;
  border: 2px solid #080;
  background: none;
  color: #080;
  cursor: pointer;
  font-size: .8rem;
  font-family: inherit;
  white-space: nowrap;
  line-height: 1.4;
}
.btn-toggle:hover { background: #080; color: #fff; }
.btn-toggle.is-done { border-color: #aaa; color: #888; }
.btn-toggle.is-done:hover { border-color: #c00; background: #c00; color: #fff; }

/* Due date shift buttons (-1d / +1d) */
.btn-shift { appearance: none; -webkit-appearance: none; background: none; border: none; outline: none; box-shadow: none; cursor: pointer; font-size: inherit; font-family: inherit; color: var(--text); text-decoration: underline; padding: 0; vertical-align: baseline; opacity: .45; }
.btn-shift:hover { opacity: 1; }

/* Done tasks */
tr.done td { opacity: .45; text-decoration: line-through; }
tr.done td a { text-decoration: line-through; }
.label-check { flex-direction: row; align-items: center; gap: .5rem; font-weight: normal; align-self: flex-end; }
.label-check input { width: auto; }

/* Pipeline filters */
.pipeline-filters {
  display: flex;
  gap: 0;
  flex: 1;
  justify-content: center;
}
.status-filters {
  display: flex;
  gap: 0;
  margin-left: auto;
}
.btn-filter {
  display: inline-block;
  padding: .3rem .8rem;
  border: 2px solid var(--black);
  border-right-width: 0;
  font-size: .85rem;
  text-decoration: none;
  color: var(--text);
  background: var(--white);
  white-space: nowrap;
  cursor: pointer;
}
.pipeline-filters .btn-filter:last-child,
.status-filters .btn-filter:last-child { border-right-width: 2px; }
.btn-filter:hover { background: var(--grey); }
.btn-filter.active { background: var(--black); color: var(--white); }
.deals-total {
  font-weight: 700;
  white-space: nowrap;
  font-size: .95rem;
  padding: .3rem .8rem;
  border: 2px solid var(--black);
  background: var(--grey);
}

/* Empty state */
.empty { color: var(--muted); font-style: italic; }

/* Form feedback */
.form-error   { color: #cc2200; margin-bottom: 1rem; }
.form-success { color: #2a7a2a; margin-bottom: 1rem; }
[data-theme="dark"] .form-error   { color: #ff6b6b; }
[data-theme="dark"] .form-success { color: #66bb66; }

/* Responsive — minimum vital */
@media (max-width: 700px) {
  .layout {
    grid-template-columns: 1fr;
  }
  aside {
    border-right: none;
    border-bottom: 2px solid var(--black);
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    padding: .6rem 1rem;
    gap: .8rem;
  }
  aside nav {
    flex-direction: row;
    flex-wrap: wrap;
    gap: .2rem;
  }
  .theme-form { margin-top: 0; margin-left: auto; }
  main { padding: 1rem; }
  .page-header { flex-wrap: wrap; gap: .5rem; }
  .pipeline-filters { flex-wrap: wrap; flex: none; justify-content: flex-start; }
  .record-nav { flex-wrap: wrap; margin-left: 0; }
  .table-wrap { overflow-x: auto; }
  dl { grid-template-columns: 120px 1fr; }
  .form-row { grid-template-columns: 1fr; }
}
