:root {
  --ink: #1a1612;
  --paper: #f3eee6;
  --sand: #e4d6be;
  --gold: #c8892a;
  --gold-deep: #8d5a12;
  --char: #221c16;
  --tile: #fffaf1;
  --line: #ddd0b8;
  --danger: #9b2c2c;
  --ok: #2f6b3a;
  --muted: #7a6c5a;
  --shadow: 0 8px 18px rgba(28, 20, 12, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font: 13px/1.35 "Segoe UI", system-ui, sans-serif;
}

body { display: flex; flex-direction: column; min-height: 100vh; }

a { color: var(--gold-deep); }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.45rem 0.9rem;
  background: var(--char);
  color: var(--paper);
}

.brand {
  display: flex;
  gap: 0.45rem;
  align-items: center;
}

.brand small, .who em {
  display: block;
  font-style: normal;
  opacity: 0.65;
  font-size: 0.7rem;
}

.brand.large { margin-bottom: 0.7rem; }

.mark {
  width: 1.45rem;
  height: 1.45rem;
  border-radius: 0.3rem;
  display: grid;
  place-items: center;
  background: var(--gold);
  color: #2a1604;
  font-size: 0.8rem;
  font-weight: 700;
}

.topbar-actions {
  display: flex;
  gap: 0.65rem;
  align-items: center;
}

.who { text-align: right; font-size: 0.85rem; }

.password-panel { position: relative; }

.password-panel summary {
  list-style: none;
  cursor: pointer;
  padding: 0.15rem 0.4rem;
  border: 1px solid #5b4a35;
  border-radius: 0.28rem;
  color: var(--paper);
  font-size: 0.75rem;
}

.password-panel summary::-webkit-details-marker { display: none; }

.password-form {
  position: absolute;
  right: 0;
  top: calc(100% + 0.4rem);
  z-index: 40;
  display: grid;
  gap: 0.4rem;
  width: min(18rem, 86vw);
  padding: 0.7rem;
  background: var(--tile);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 0.4rem;
  box-shadow: var(--shadow);
}

.password-form .flash { margin: 0; }

.team-banner {
  display: flex;
  gap: 0.7rem;
  align-items: flex-start;
  justify-content: space-between;
  padding: 0.4rem 0.9rem;
  background: #2c2418;
  color: #e8dcc4;
  border-bottom: 1px solid #5b4a35;
}

.team-banner.has-notice {
  background: var(--gold-deep);
  color: #fff8ea;
  border-bottom-color: var(--gold);
}

.team-banner-main { flex: 1; min-width: 0; }

.team-banner-text,
.team-banner-empty {
  margin: 0;
  white-space: pre-wrap;
}

.team-banner-label {
  display: inline-block;
  margin-right: 0.4rem;
  padding: 0.02rem 0.35rem;
  border: 1px solid rgba(255, 248, 234, 0.45);
  border-radius: 0.22rem;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.team-banner-empty { opacity: 0.7; font-size: 0.8rem; }

.banner-edit-panel {
  flex: 0 0 auto;
  min-width: 12rem;
}

.banner-edit-panel summary {
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 650;
  color: inherit;
}

.banner-edit {
  display: grid;
  gap: 0.35rem;
  margin-top: 0.35rem;
}

.banner-edit textarea {
  min-width: 16rem;
  max-width: min(36rem, 70vw);
}

.team-banner.has-notice .banner-edit textarea {
  background: #fff8ea;
}

.banner-edit button { justify-self: start; }

.team-banner .flash { margin-top: 0.35rem; }

main { padding: 0.7rem 0.9rem 1.2rem; flex: 1; }
.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.login-card, .panel, .user-tile {
  background: var(--tile);
  border: 1px solid var(--line);
}

.login-card {
  width: min(360px, 92vw);
  padding: 1.1rem;
  border-radius: 0.6rem;
  box-shadow: var(--shadow);
}

.dash-head {
  display: flex;
  justify-content: space-between;
  gap: 0.7rem;
  align-items: center;
  margin-bottom: 0.55rem;
}

.dash-head h1 { margin: 0; font-size: 1.15rem; font-weight: 650; }

.panel {
  padding: 0.35rem 0.55rem;
  border-radius: 0.4rem;
}

.panel summary { cursor: pointer; font-weight: 600; font-size: 0.82rem; }

.stack { display: grid; gap: 0.45rem; }
.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.4rem;
  align-items: center;
}

.inline-form input,
.inline-form select { width: auto; min-width: 8rem; }

label { display: grid; gap: 0.15rem; font-size: 0.8rem; }

input, select, textarea, button { font: inherit; }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fffdf8;
  color: var(--ink);
  border-radius: 0.28rem;
  padding: 0.28rem 0.4rem;
}

button, .badge {
  border-radius: 0.28rem;
  border: 1px solid transparent;
}

button {
  cursor: pointer;
  padding: 0.28rem 0.55rem;
  background: var(--sand);
}

button.primary {
  background: var(--gold);
  color: #2a1604;
  font-weight: 650;
}

button.ghost {
  background: transparent;
  border-color: var(--line);
  color: inherit;
}

button.danger {
  background: transparent;
  color: var(--danger);
  border-color: #e3b4b4;
}

button.compact { padding: 0.15rem 0.4rem; font-size: 0.75rem; }
button:disabled { opacity: 0.45; cursor: not-allowed; }

.topbar button.ghost { color: var(--paper); border-color: #5b4a35; }

.flash-stack { padding: 0.4rem 0.9rem 0; }
.flash {
  padding: 0.3rem 0.5rem;
  border-radius: 0.3rem;
  margin: 0 0 0.4rem;
  font-size: 0.82rem;
}
.flash.error { background: #f8d7d3; color: var(--danger); }
.flash.ok { background: #d9edd8; color: var(--ok); }

.hint, .muted, time { color: var(--muted); font-size: 0.75rem; }
code { font-family: Consolas, monospace; }

.grid-stack { min-height: 16rem; }

.grid-stack > .grid-stack-item > .ui-resizable-handle {
  background: none !important;
  background-image: none !important;
  -webkit-transform: none !important;
  transform: none !important;
}

.grid-stack > .grid-stack-item > .ui-resizable-se,
.grid-stack > .grid-stack-item > .ui-resizable-sw {
  width: 12px !important;
  height: 12px !important;
  margin: 0 !important;
  padding: 0 !important;
  box-sizing: border-box;
  z-index: 20;
}

.grid-stack > .grid-stack-item > .ui-resizable-se::after,
.grid-stack > .grid-stack-item > .ui-resizable-sw::after {
  content: "";
  position: absolute;
  width: 12px;
  height: 12px;
  box-sizing: border-box;
  opacity: 0.72;
  pointer-events: none;
}

.grid-stack > .grid-stack-item > .ui-resizable-se {
  right: var(--gs-item-margin-right, 10px) !important;
  bottom: var(--gs-item-margin-bottom, -10px) !important;
  left: auto !important;
  top: auto !important;
}

.grid-stack > .grid-stack-item > .ui-resizable-se::after {
  right: 0;
  bottom: 0;
  border-right: 2px solid var(--gold-deep);
  border-bottom: 2px solid var(--gold-deep);
  border-bottom-right-radius: 0.35rem;
}

.grid-stack > .grid-stack-item > .ui-resizable-sw {
  left: var(--gs-item-margin-left, 10px) !important;
  bottom: var(--gs-item-margin-bottom, -10px) !important;
  right: auto !important;
  top: auto !important;
}

.grid-stack > .grid-stack-item > .ui-resizable-sw::after {
  left: 0;
  bottom: 0;
  border-left: 2px solid var(--gold-deep);
  border-bottom: 2px solid var(--gold-deep);
  border-bottom-left-radius: 0.35rem;
}

.grid-stack > .grid-stack-item:hover > .ui-resizable-se::after,
.grid-stack > .grid-stack-item:hover > .ui-resizable-sw::after {
  opacity: 1;
}

.grid-stack > .grid-stack-item > .ui-resizable-s {
  height: 5px;
  left: 14px;
  right: 14px;
  bottom: var(--gs-item-margin-bottom, 10px) !important;
  width: auto;
}

.grid-stack > .grid-stack-item > .ui-resizable-e {
  width: 5px;
  top: 2.2rem;
  bottom: 14px;
  height: auto;
  right: var(--gs-item-margin-right, 10px) !important;
}

.grid-stack > .grid-stack-item > .ui-resizable-w {
  width: 5px;
  top: 2.2rem;
  bottom: 14px;
  height: auto;
  left: var(--gs-item-margin-left, 10px) !important;
}

.user-tile {
  height: 100%;
  border-radius: 0.45rem;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.user-tile.mine { outline: 1px solid var(--gold); }

.tile-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.35rem 0.5rem 0.2rem;
  cursor: grab;
}

.tile-tools {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.tile-body,
.tile-body input,
.tile-body textarea,
.tile-body select,
.tile-body button {
  pointer-events: auto;
}

.tile-head small { display: block; color: var(--muted); font-size: 0.7rem; }

.badge {
  font-size: 0.65rem;
  padding: 0.05rem 0.35rem;
  border: 1px solid var(--line);
  color: var(--muted);
}

.subnav {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  padding: 0 0.45rem;
  border-bottom: 1px solid var(--line);
}

.tab {
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 0.25rem 0.45rem;
  font-size: 0.78rem;
}

.tab.active {
  background: transparent;
  border-bottom-color: var(--gold);
  font-weight: 650;
}

.task-subnav {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  margin: 0 0 0.4rem;
  border-bottom: 1px solid var(--line);
}

.task-subnav .tab[data-task-tab="overdue"].active {
  border-bottom-color: var(--danger);
  color: var(--danger);
}

.task.overdue .task-fields input[type="date"],
.task.overdue time {
  color: var(--danger);
  font-weight: 650;
}

.task-block.leftover {
  border-style: dashed;
}

.task-block.leftover > .task.done {
  opacity: 0.72;
}

.task-leftover-label {
  margin: 0 0 0 1.4rem;
  font-size: 0.72rem;
}

.tile-body {
  flex: 1;
  overflow: auto;
  padding: 0.4rem;
}

.subtile { display: grid; gap: 0.4rem; }

.filters { display: block; }

.add-row, .inline-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
  gap: 0.28rem;
  align-items: end;
}

.table-wrap { overflow: auto; max-height: 22rem; }

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

table.data th, table.data td {
  text-align: left;
  padding: 0.15rem 0.2rem;
  border-bottom: 1px solid #efe0c4;
  vertical-align: middle;
}

.row-actions { display: flex; gap: 0.2rem; white-space: nowrap; }

.task-list, .note-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.28rem;
}

.task-list { gap: 0.55rem; }

.task {
  display: grid;
  grid-template-columns: 1.05rem minmax(0, 1fr) auto;
  gap: 0.35rem;
  align-items: center;
}

.task > input[type="checkbox"] {
  margin: 0;
  width: 1.05rem;
  height: 1.05rem;
  justify-self: center;
}

.task.done .task-fields input[name="description"],
.task.done span { text-decoration: line-through; opacity: 0.65; }

.task-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(5.4rem, 6.4rem) auto;
  gap: 0.25rem;
  align-items: center;
  min-width: 0;
}

.task-fields input[name="description"],
.task-fields span {
  min-width: 0;
}

.task-fields time {
  color: var(--muted);
  font-size: 0.75rem;
  white-space: nowrap;
}

.task-block {
  display: grid;
  gap: 0.35rem;
  padding: 0.4rem 0.4rem 0.45rem;
  border: 1px solid var(--line);
  border-radius: 0.35rem;
  background: #fffdf8;
}

.task-extras {
  display: grid;
  gap: 0.35rem;
  min-width: 0;
  margin-left: 1.4rem;
}

.task-nest {
  display: grid;
  gap: 0.3rem;
  padding: 0.35rem 0.35rem 0.35rem 0.5rem;
  border-left: 2px solid var(--gold);
  border-radius: 0 0.3rem 0.3rem 0;
  background: rgba(200, 137, 42, 0.07);
}

.task-children {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.4rem;
}

.task-child {
  display: grid;
  gap: 0.25rem;
  min-width: 0;
}

.task-child .task-notes {
  margin-left: 1.4rem;
}

.add-subtask,
.add-task {
  display: grid;
  gap: 0.25rem;
  align-items: center;
  min-width: 0;
}

.add-subtask {
  grid-template-columns: 1.05rem minmax(0, 1fr) minmax(5.4rem, 6.4rem) auto 1.4rem;
}

.add-subtask::before {
  content: "";
  width: 1.05rem;
}

.add-task {
  grid-template-columns: minmax(0, 1fr) minmax(5.4rem, 6.4rem) auto;
  padding-top: 0.15rem;
  border-top: 1px solid var(--line);
}

.add-subtask input[name="description"],
.add-task input[name="description"] {
  min-width: 0;
}

.task-fields input[type="date"],
.add-subtask input[type="date"],
.add-task input[type="date"] {
  width: 100%;
  min-width: 0;
  max-width: 6.4rem;
}

.task-notes { min-width: 0; }

.task-notes > summary {
  cursor: pointer;
  color: var(--gold-deep);
  font-size: 0.75rem;
  font-weight: 600;
}

.task-notes .note-list,
.task-notes .note-compose {
  margin-top: 0.28rem;
}

.task-notes .note-compose textarea {
  min-height: 2.4rem;
}

.task-notes .note-delete { display: inline-flex; }

.task-notes .note-edit {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.35rem;
  align-items: start;
}

.task-notes .note-save { display: inline-flex; }

.note-list li {
  display: flex;
  align-items: flex-start;
  gap: 0.35rem;
  border: 1px solid #efe0c4;
  border-radius: 0.3rem;
  padding: 0.3rem;
}

.note-list li p,
.note-text {
  margin: 0;
  flex: 1;
  min-width: 0;
  white-space: pre-wrap;
}

.note-body {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 0.2rem;
}

.note-body .badge { justify-self: start; }

.note-attach {
  display: grid;
  gap: 0.15rem;
}

.contact-notes-row td {
  border-bottom-color: var(--line);
  padding-bottom: 0.45rem;
}

.contact-notes summary {
  cursor: pointer;
  color: var(--gold-deep);
  font-size: 0.75rem;
  font-weight: 600;
}

.contact-notes-panel {
  margin-top: 0.35rem;
  display: grid;
  gap: 0.35rem;
}

.note-list li.muted { display: block; }

.notes-toolbar,
.contacts-toolbar {
  display: flex;
  justify-content: flex-end;
}

.contact-field,
.contact-save,
.contact-delete { display: none; }

.contact-scope.editing .contact-text { display: none; }

.contact-scope.editing .contact-field { display: block; }

.contact-scope.editing .contact-save,
.contact-scope.editing .contact-delete { display: inline-flex; }

.contact-scope.editing .contacts-edit-toggle {
  border-color: var(--gold);
  font-weight: 650;
}

.note-delete,
.note-edit,
.note-save { display: none; }

.note-scope.editing .note-delete { display: inline-flex; }

.note-scope.editing .note-text { display: none; }

.note-scope.editing .note-edit {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.35rem;
  align-items: start;
}

.note-scope.editing .note-save { display: inline-flex; }

.note-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: flex-start;
}

.note-att {
  position: relative;
  display: inline-flex;
  align-items: center;
  max-width: 100%;
}

.note-thumb {
  display: block;
  border: 1px solid var(--line);
  border-radius: 0.28rem;
  overflow: hidden;
  background: #fffdf8;
}

.note-thumb img {
  display: block;
  width: 4.5rem;
  height: 3.4rem;
  object-fit: cover;
}

.note-file {
  display: inline-flex;
  align-items: baseline;
  gap: 0.3rem;
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0.12rem 0.35rem;
  border: 1px solid var(--line);
  border-radius: 0.28rem;
  background: #fffdf8;
  color: inherit;
  text-decoration: none;
  font-size: 0.75rem;
}

.company-file-delete,
.note-att-delete { display: none; }

.company-scope .company-file-delete {
  display: inline-flex;
  position: absolute;
  top: -0.3rem;
  right: -0.3rem;
  min-width: 1.1rem;
  justify-content: center;
  background: var(--tile);
}

.note-scope.editing .note-att-delete {
  display: inline-flex;
  position: absolute;
  top: -0.3rem;
  right: -0.3rem;
  min-width: 1.1rem;
  justify-content: center;
  background: var(--tile);
}

.note-upload {
  display: grid;
  gap: 0.15rem;
  min-width: 0;
}

.note-edit .note-upload {
  display: none;
  grid-column: 1 / -1;
}

.note-scope.editing .note-edit .note-upload { display: grid; }

.note-upload input[type="file"] {
  width: 100%;
  padding: 0.15rem 0;
  border: 0;
  background: transparent;
}

.note-upload-names {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-edit textarea {
  width: 100%;
  min-width: 0;
  resize: vertical;
}

.note-scope.editing .notes-edit-toggle {
  border-color: var(--gold);
  font-weight: 650;
}

.note-compose {
  display: grid;
  gap: 0.35rem;
}

.note-compose textarea {
  width: 100%;
  min-width: 0;
  resize: vertical;
}

.note-compose button { justify-self: start; }

.note-list textarea, .add-row textarea { resize: vertical; }

.company-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.55rem;
}

.company-card {
  display: grid;
  gap: 0.35rem;
  padding: 0.45rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 0.35rem;
  background: #fffdf8;
}

.company-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.25rem 0.6rem;
}

.company-people {
  margin: 0;
  font-size: 0.74rem;
}

.company-upload,
.company-compose {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.35rem;
  align-items: end;
}

.company-compose {
  margin-top: 0.55rem;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr) auto;
}

@media (max-width: 800px) {
  .company-upload,
  .company-compose {
    grid-template-columns: minmax(0, 1fr);
  }

  .dash-head { flex-direction: column; align-items: stretch; }
  .task-fields,
  .add-task {
    grid-template-columns: minmax(0, 1fr) minmax(5.4rem, 6.4rem) auto;
  }
  .add-subtask {
    grid-template-columns: 1.05rem minmax(0, 1fr) minmax(5.4rem, 6.4rem) auto 1.4rem;
  }
  .team-banner { flex-direction: column; }
  .banner-edit textarea { min-width: 0; width: 100%; max-width: none; }
}
