:root {
  --bg-0: #f6f4ee;
  --bg-1: #ece8dd;
  --ink: #132026;
  --muted: #5e6a70;
  --brand: #0f4c3a;
  --brand-strong: #0b3a2d;
  --danger: #a63636;
  --card: #fffdf8;
  --edge: #d5d0c2;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Trebuchet MS", "Gill Sans", "Franklin Gothic Medium", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 0% 0%, #ffffff 0, transparent 35%),
    radial-gradient(circle at 90% 10%, #dbe7de 0, transparent 35%),
    linear-gradient(160deg, var(--bg-0), var(--bg-1));
  min-height: 100vh;
}

html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--edge);
  background: rgba(255, 253, 248, 0.82);
  backdrop-filter: blur(4px);
}

.header-main {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-width: 0;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin-left: auto;
}

.header-user-info {
  display: grid;
  gap: 0.12rem;
}

.header-user-info small {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.15;
}

.app-header h1 {
  margin: 0;
  letter-spacing: 0.04em;
}

.app-header p {
  margin: 0.2rem 0 0;
  color: var(--muted);
}

.logo {
  width: 64px;
  height: 64px;
  object-fit: contain;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--edge);
  padding: 0.4rem;
}

.container {
  width: min(1200px, 100%);
  margin: 1.1rem auto 2rem;
  padding: 0 0.7rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--edge);
  border-radius: 16px;
  padding: 1rem;
  box-shadow: 0 8px 25px rgba(30, 43, 56, 0.06);
  max-width: 100%;
  min-width: 0;
}

.hidden {
  display: none !important;
}

.grid {
  display: grid;
  gap: 1rem;
}

.two-cols {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.grid-form label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.92rem;
  min-width: 0;
}

.grid-form label.checkbox-inline {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

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

.grid-form .full {
  grid-column: 1 / -1;
}

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

input,
select,
textarea {
  border: 1px solid #bcc5c7;
  border-radius: 10px;
  padding: 0.56rem 0.62rem;
  background: #fff;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

button {
  border: none;
  border-radius: 10px;
  padding: 0.62rem 0.86rem;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  transition: transform 0.15s ease, background-color 0.15s ease;
  max-width: 100%;
}

button:hover {
  transform: translateY(-1px);
  background: var(--brand-strong);
}

button.danger {
  background: var(--danger);
}

.tabs {
  display: flex;
  gap: 0.4rem;
  margin: 1rem 0;
}

.tab {
  background: #d6ded4;
  color: #2d3835;
}

.tab.active {
  background: var(--brand);
  color: #fff;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.role-chip {
  margin-left: 0.5rem;
  font-size: 0.82rem;
  color: #fff;
  background: #3f4d57;
  padding: 0.18rem 0.46rem;
  border-radius: 999px;
}

.row-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
  min-width: 0;
}

.row-actions > * {
  min-width: 0;
  max-width: 100%;
}

.row-actions.compact {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.row-actions.compact > * {
  max-width: none;
}

.row-actions.compact select,
.row-actions.compact input[type="month"] {
  min-width: 170px;
  flex: 1 1 170px;
}

.row-actions.compact button {
  min-width: 150px;
  flex: 1 1 150px;
}

.list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
}

.list {
  display: grid;
  gap: 0.68rem;
  margin-top: 0.8rem;
}

.item {
  border: 1px solid #d3dddf;
  background: #fff;
  border-radius: 12px;
  padding: 0.8rem;
  max-width: 100%;
  min-width: 0;
}

.item.editable-note {
  cursor: pointer;
}

.item.editing-note {
  border-color: #0f4c3a;
  box-shadow: inset 0 0 0 1px rgba(15, 76, 58, 0.24);
}

.item h3 {
  margin: 0;
  font-size: 1rem;
}

.item p {
  margin: 0.4rem 0;
  color: #3b4850;
  font-size: 0.9rem;
}

.item .row-actions {
  margin-top: 0.5rem;
}

.link-button {
  border: none;
  background: transparent;
  color: var(--brand);
  margin-top: 0.8rem;
  padding: 0;
}

.error {
  color: var(--danger);
  min-height: 1.2rem;
}

.hint {
  color: #2e5f57;
  min-height: 1.2rem;
}

.attachments-editor {
  border: 1px solid #d3dddf;
  border-radius: 12px;
  padding: 0.55rem;
  min-height: 58px;
  background: #fff;
}

.attachment-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem;
  border-bottom: 1px solid #edf0f2;
}

.attachment-row:last-child {
  border-bottom: none;
}

.attachment-thumb {
  width: 58px;
  height: 58px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid #d0d8da;
  background: #fff;
}

.attachment-thumb.file-tile {
  display: grid;
  place-items: center;
  font-size: 0.76rem;
  font-weight: 700;
  color: #344851;
}

.attachment-meta {
  flex: 1;
  min-width: 0;
  font-size: 0.87rem;
  overflow-wrap: anywhere;
}

.attachment-meta small {
  color: var(--muted);
}

.attachments {
  margin-top: 0.8rem;
}

.attachments-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 0.65rem;
}

.expense-attachment-card {
  border: 1px solid #d9e1e3;
  border-radius: 10px;
  padding: 0.45rem;
  background: #fff;
  display: grid;
  gap: 0.35rem;
  align-content: start;
}

.attachment-preview-btn {
  padding: 0;
  border: 1px solid #d0d8da;
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  cursor: zoom-in;
}

.attachment-preview-image {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
}

.attachment-name-btn {
  border: none;
  background: transparent;
  text-align: left;
  padding: 0;
  font-size: 0.82rem;
  color: #123f44;
  text-decoration: underline;
  cursor: pointer;
  overflow-wrap: anywhere;
}

.attachment-file-icon {
  height: 94px;
  border: 1px solid #d0d8da;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-weight: 700;
  color: #2f4550;
  background: #f3f6f8;
}

.expense-attachment-card small {
  color: var(--muted);
  font-size: 0.76rem;
}

.attachment-viewer-card {
  width: min(1100px, 100%);
  max-height: 95vh;
  background: #0f1418;
  border: 1px solid #33414b;
  border-radius: 14px;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr;
}

.attachment-viewer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid #2c3942;
  color: #f2f6f7;
}

.attachment-viewer-head button {
  border: 1px solid #4f6774;
  background: transparent;
  color: #f2f6f7;
  padding: 0.35rem 0.65rem;
}

.attachment-viewer-body {
  display: grid;
  place-items: center;
  padding: 0.65rem;
}

.attachment-viewer-body img {
  max-width: 100%;
  max-height: calc(95vh - 84px);
  object-fit: contain;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(19, 32, 38, 0.55);
  display: grid;
  place-items: center;
  z-index: 300;
  padding: 1rem;
}

.modal-card {
  width: min(920px, 100%);
  max-height: 94vh;
  overflow: auto;
  background: #fffef8;
  border: 1px solid var(--edge);
  border-radius: 16px;
  padding: 1rem;
}

.crop-stage {
  position: relative;
  margin: 0.7rem auto 1rem;
  width: min(100%, 840px);
  border: 1px solid #d3dadd;
  border-radius: 10px;
  background: #eef3f5;
  overflow: hidden;
  touch-action: none;
}

.crop-stage img {
  width: 100%;
  height: auto;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

.crop-rect {
  position: absolute;
  border: 2px solid #0f4c3a;
  background: rgba(15, 76, 58, 0.16);
  cursor: move;
}

.crop-handle {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 999px;
  background: #0f4c3a;
  border: 2px solid #fff;
}

.crop-handle.nw {
  top: -8px;
  left: -8px;
  cursor: nwse-resize;
}

.crop-handle.ne {
  top: -8px;
  right: -8px;
  cursor: nesw-resize;
}

.crop-handle.sw {
  bottom: -8px;
  left: -8px;
  cursor: nesw-resize;
}

.crop-handle.se {
  bottom: -8px;
  right: -8px;
  cursor: nwse-resize;
}

@media (max-width: 900px) {
  .two-cols,
  .grid-form {
    grid-template-columns: 1fr;
  }

  .topbar,
  .list-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .app-header {
    align-items: flex-start;
  }

  .header-user {
    width: 100%;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.45rem;
  }

  .header-user > button {
    order: 1;
  }

  .header-user-info {
    order: 2;
    text-align: right;
  }

  .row-actions.compact {
    width: 100%;
  }

  .row-actions.compact > * {
    max-width: unset;
    flex: 1;
  }

  .row-actions.compact select,
  .row-actions.compact input[type="month"],
  .row-actions.compact button {
    min-width: 0;
    flex: 1 1 100%;
  }

  .container {
    padding: 0 0.5rem;
    margin: 0.8rem auto 1.2rem;
  }

  .card {
    border-radius: 12px;
    padding: 0.85rem;
  }

  .attachment-thumb {
    width: 50px;
    height: 50px;
  }

  .attachments-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .attachment-viewer-card {
    max-height: 100vh;
    border-radius: 0;
  }
}
