:root {
  --sky: #0795d7;
  --sky-dark: #057ab0;
  --sky-soft: #e8f8ff;
  --mint: #19b99a;
  --amber: #e6a000;
  --rose: #dd4b6a;
  --ink: #17324d;
  --muted: #668094;
  --line: rgba(77, 124, 153, 0.16);
  --panel: rgba(255, 255, 255, 0.78);
  --shadow: 0 18px 50px rgba(22, 95, 136, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(231, 248, 255, 0.9), rgba(255, 255, 255, 0.92) 48%, rgba(236, 255, 250, 0.82));
  font-size: 15px;
}

a {
  color: var(--sky-dark);
  text-decoration: none;
}

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

.app-layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px 1fr;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 18px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.68);
  backdrop-filter: blur(18px);
  display: flex;
  flex-direction: column;
  z-index: 30;
}

.brand,
.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
  background: linear-gradient(135deg, #07a9ef, #19b99a);
  box-shadow: 0 10px 26px rgba(7, 149, 215, 0.28);
}

.brand strong,
.auth-brand strong {
  display: block;
  font-size: 16px;
}

.brand small,
.auth-brand small {
  display: block;
  margin-top: 2px;
}

.nav-list {
  margin-top: 34px;
  display: grid;
  gap: 8px;
}

.nav-link {
  min-height: 44px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  color: var(--muted);
  font-weight: 650;
}

.nav-link i {
  color: var(--sky-dark);
}

.nav-link:hover,
.nav-link.active {
  background: rgba(7, 149, 215, 0.1);
  color: var(--ink);
}

.sidebar-footer {
  margin-top: auto;
}

.main {
  min-width: 0;
}

.topbar {
  min-height: 86px;
  display: flex;
  align-items: center;
  gap: 16px;
  justify-content: space-between;
  padding: 20px 32px 8px;
}

.topbar h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.15;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.66);
}

.content {
  padding: 20px 32px 42px;
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}

.quick-actions a {
  min-height: 96px;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.72);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  font-weight: 800;
}

.quick-actions i {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(135deg, var(--sky), var(--mint));
}

.panel,
.stat-card,
.auth-card,
.invoice-document {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.panel {
  padding: 22px;
  margin-bottom: 22px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.panel-header h2 {
  margin: 0;
  font-size: 18px;
}

.panel-header p {
  margin: 4px 0 0;
  color: var(--muted);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}

.simple-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}

.stat-card {
  padding: 18px;
}

.stat-card span {
  width: 38px;
  height: 38px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--sky);
  margin-bottom: 14px;
}

.stat-card small,
.stat-card strong {
  display: block;
}

.stat-card strong {
  margin-top: 6px;
  font-size: 22px;
}

.dashboard-grid,
.two-column,
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px;
}

.simple-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.82fr) minmax(320px, 1fr);
  gap: 22px;
  align-items: start;
}

.simple-terms-panel {
  grid-column: 1;
}

.simple-invoice-panel {
  grid-column: 2;
  grid-row: 1 / span 2;
}

.span-2 {
  grid-column: span 2;
}

.inner-grid {
  gap: 14px;
}

.form-stack,
.form-grid label,
.panel label {
  display: grid;
  gap: 8px;
}

.form-stack {
  gap: 15px;
}

label span {
  color: var(--muted);
  font-weight: 700;
  font-size: 13px;
}

.form-control {
  width: 100%;
  min-height: 44px;
  border: 1px solid rgba(81, 129, 155, 0.22);
  border-radius: 13px;
  padding: 10px 12px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.82);
  font: inherit;
  font-size: 16px;
  outline: none;
}

.simple-input {
  min-height: 52px;
  font-size: 17px;
}

textarea.form-control {
  resize: vertical;
  line-height: 1.5;
}

.form-control:focus {
  border-color: rgba(7, 149, 215, 0.72);
  box-shadow: 0 0 0 4px rgba(7, 149, 215, 0.1);
}

.btn,
.icon-button {
  border: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font: inherit;
  font-weight: 750;
}

.btn {
  min-height: 42px;
  border-radius: 13px;
  padding: 10px 15px;
  white-space: nowrap;
}

.btn-sm {
  min-height: 36px;
  padding: 8px 12px;
}

.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--sky), #18acd2);
  box-shadow: 0 12px 26px rgba(7, 149, 215, 0.22);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.58;
  box-shadow: none;
}

.btn-soft {
  color: var(--sky-dark);
  background: rgba(7, 149, 215, 0.1);
}

.icon-button {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  color: var(--sky-dark);
  background: rgba(7, 149, 215, 0.1);
  flex: 0 0 38px;
  line-height: 1;
}

.btn i,
.icon-button i {
  display: grid;
  place-items: center;
  line-height: 1;
}

.icon-button.danger {
  color: var(--rose);
  background: rgba(221, 75, 106, 0.1);
}

.icon-button.mini {
  width: 30px;
  height: 30px;
  flex-basis: 30px;
  border-radius: 10px;
  font-size: 13px;
}

.mobile-menu {
  display: none;
}

.filters {
  display: grid;
  grid-template-columns: 1fr 190px auto;
  gap: 12px;
  margin-bottom: 18px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

.compact .data-table {
  min-width: 520px;
}

.data-table th,
.data-table td {
  padding: 13px 12px;
  text-align: left;
  border-bottom: 1px solid rgba(81, 129, 155, 0.12);
  vertical-align: middle;
}

.data-table th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.data-table td strong,
.data-table td small {
  display: block;
}

.actions-col {
  width: 230px;
}

.table-actions {
  display: flex;
  align-items: center;
  gap: 7px;
}

.table-actions form {
  margin: 0;
  display: inline-flex;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 800;
}

.badge-success { color: #04785f; background: rgba(25, 185, 154, 0.14); }
.badge-warning { color: #996600; background: rgba(230, 160, 0, 0.16); }
.badge-danger { color: #a8334d; background: rgba(221, 75, 106, 0.14); }
.badge-secondary { color: #607181; background: rgba(96, 113, 129, 0.14); }
.badge-info { color: #0a6b83; background: rgba(16, 171, 205, 0.14); }
.badge-primary { color: #057ab0; background: rgba(7, 149, 215, 0.14); }

.alert {
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 16px;
  border: 1px solid transparent;
}

.alert-success {
  color: #04785f;
  background: rgba(25, 185, 154, 0.12);
  border-color: rgba(25, 185, 154, 0.22);
}

.alert-danger {
  color: #a8334d;
  background: rgba(221, 75, 106, 0.1);
  border-color: rgba(221, 75, 106, 0.2);
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 30px !important;
}

.details-list {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 12px;
}

.details-list dt {
  color: var(--muted);
  font-weight: 800;
}

.details-list dd {
  margin: 0;
}

.logo-row {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 18px;
  align-items: center;
}

.logo-preview {
  width: 96px;
  height: 96px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: rgba(7, 149, 215, 0.1);
  overflow: hidden;
  color: var(--sky-dark);
  font-size: 28px;
}

.logo-preview img,
.invoice-logo {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.invoice-item-row {
  display: grid;
  grid-template-columns: 1.25fr 1fr 0.75fr 1.35fr 38px;
  gap: 10px;
  align-items: end;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.58);
  margin-bottom: 12px;
}

.invoice-item-row .wide {
  min-width: 180px;
}

.building-manager {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.building-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.62);
  padding: 14px;
}

.building-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.building-card-header strong,
.building-card-header small {
  display: block;
}

.room-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

.room-chip {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(81, 129, 155, 0.16);
  border-radius: 12px;
  padding: 4px 4px 4px 10px;
  background: rgba(255, 255, 255, 0.78);
  font-weight: 750;
}

.room-chip form {
  display: inline-flex;
  margin: 0;
}

.simple-empty {
  grid-column: 1 / -1;
}

.totals-list,
.summary-box {
  display: grid;
  gap: 11px;
}

.totals-list div,
.summary-box div {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  color: var(--muted);
}

.totals-list strong,
.summary-box strong {
  color: var(--ink);
}

.summary-box .grand {
  border-top: 1px solid var(--line);
  padding-top: 12px;
  font-size: 18px;
}

.toggle-row {
  display: flex !important;
  align-items: center;
  gap: 10px;
  min-height: 44px;
}

.toggle-row input {
  width: 19px;
  height: 19px;
  accent-color: var(--sky);
}

.form-actions,
.action-bar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.sticky-actions {
  position: sticky;
  bottom: 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
}

.invoice-page-shell {
  width: 100%;
  overflow-x: auto;
  padding-bottom: 14px;
}

.invoice-document {
  width: min(100%, 920px);
  min-width: 760px;
  margin: 0 auto;
  padding: 34px;
  background: rgba(255, 255, 255, 0.92);
}

.invoice-doc-header,
.invoice-doc-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 24px;
}

.invoice-summary {
  display: grid;
  grid-template-columns: 1fr minmax(240px, 0.42fr);
  gap: 24px;
}

.invoice-summary .summary-box {
  grid-column: 2;
}

.invoice-doc-header {
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 22px;
}

.invoice-doc-header h1,
.invoice-doc-header h2 {
  margin: 0 0 8px;
}

.invoice-doc-header p,
.invoice-doc-grid p {
  margin: 4px 0;
  color: var(--muted);
}

.invoice-doc-meta {
  text-align: right;
}

.invoice-lines th:first-child,
.invoice-lines td:first-child {
  width: 42px;
}

.invoice-lines th:last-child,
.invoice-lines td:last-child {
  text-align: right;
  white-space: nowrap;
}

.invoice-doc-grid,
.invoice-summary {
  margin-top: 22px;
}

.amount-words {
  align-self: start;
  border-radius: 16px;
  padding: 15px;
  background: rgba(7, 149, 215, 0.08);
  margin-top: 15px;
}

.auth-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}

.auth-card {
  width: min(100%, 460px);
  padding: 28px;
}

.auth-card h1 {
  margin: 26px 0 8px;
}

.auth-card p {
  color: var(--muted);
}

.sidebar-backdrop {
  display: none;
}

@media (max-width: 1180px) {
  .stats-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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

  .building-manager {
    grid-template-columns: 1fr;
  }

  .invoice-item-row {
    grid-template-columns: repeat(4, minmax(150px, 1fr)) 38px;
  }
}

@media (max-width: 900px) {
  .app-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    left: 0;
    transform: translateX(-105%);
    transition: transform 180ms ease;
    width: 280px;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-backdrop.show {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(17, 37, 56, 0.28);
    z-index: 20;
  }

  .mobile-menu {
    display: inline-flex;
  }

  .topbar,
  .content {
    padding-left: 18px;
    padding-right: 18px;
  }

  .topbar-user {
    display: none;
  }

  .dashboard-grid,
  .simple-grid,
  .two-column,
  .form-grid,
  .invoice-doc-header,
  .invoice-doc-grid,
  .invoice-summary {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: span 1;
  }

  .filters {
    grid-template-columns: 1fr;
  }

  .invoice-doc-meta {
    text-align: left;
  }

  .simple-terms-panel,
  .simple-invoice-panel {
    grid-column: auto;
    grid-row: auto;
  }

  .invoice-page-shell .invoice-doc-header,
  .invoice-page-shell .invoice-doc-grid {
    grid-template-columns: 1.4fr 1fr;
  }

  .invoice-page-shell .invoice-summary {
    grid-template-columns: 1fr minmax(220px, 0.45fr);
  }

  .invoice-page-shell .invoice-doc-meta {
    text-align: right;
  }
}

@media (max-width: 640px) {
  body {
    font-size: 14px;
  }

  .stats-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .simple-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .simple-stats .stat-card {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr);
    gap: 4px 9px;
    align-items: center;
    padding: 12px;
  }

  .simple-stats .stat-card span {
    grid-row: span 2;
    width: 34px;
    height: 34px;
    margin-bottom: 0;
    border-radius: 11px;
  }

  .simple-stats .stat-card small {
    min-width: 0;
    font-size: 11px;
    line-height: 1.15;
  }

  .simple-stats .stat-card strong {
    min-width: 0;
    margin-top: 0;
    font-size: 17px;
    line-height: 1.15;
    overflow-wrap: anywhere;
  }

  .quick-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .quick-actions a {
    min-height: 88px;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    padding: 14px;
    font-size: 13px;
    line-height: 1.25;
  }

  .quick-actions i {
    width: 36px;
    height: 36px;
    flex-basis: 36px;
  }

  .topbar {
    min-height: 72px;
    align-items: center;
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr);
    gap: 10px;
  }

  .topbar h1 {
    font-size: 22px;
    overflow-wrap: anywhere;
  }

  .mobile-menu {
    width: 42px;
    height: 42px;
    flex-basis: 42px;
  }

  .content {
    padding: 14px 10px 96px;
  }

  .panel,
  .invoice-document {
    padding: 14px;
    border-radius: 14px;
    margin-bottom: 14px;
  }

  .panel-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .panel-header .btn,
  .filters .btn {
    width: 100%;
  }

  .building-card {
    padding: 12px;
    border-radius: 14px;
  }

  .building-card-header {
    align-items: center;
  }

  .room-chip-list {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .room-chip {
    width: 100%;
    justify-content: space-between;
  }

  .invoice-item-row {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .invoice-item-row .icon-button {
    width: 100%;
  }

  .logo-row {
    grid-template-columns: 1fr;
  }

  .data-table {
    min-width: 0;
  }

  .data-table thead {
    display: none;
  }

  .data-table,
  .data-table tbody,
  .data-table tr,
  .data-table td {
    display: block;
    width: 100%;
  }

  .data-table tr {
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 10px;
    margin-bottom: 10px;
    background: rgba(255, 255, 255, 0.7);
  }

  .data-table td {
    border-bottom: 0;
    padding: 7px 4px;
  }

  .invoice-page-shell .invoice-document {
    width: 100%;
    min-width: 0;
    padding: 28px;
    border-radius: 18px;
    margin-bottom: 14px;
    font-size: 10px;
  }

  .invoice-page-shell .invoice-doc-header,
  .invoice-page-shell .invoice-doc-grid,
  .invoice-page-shell .invoice-summary {
    gap: 12px;
  }

  .invoice-page-shell .invoice-doc-header {
    padding-bottom: 14px;
    margin-bottom: 14px;
  }

  .invoice-page-shell .invoice-doc-grid,
  .invoice-page-shell .invoice-summary {
    margin-top: 14px;
  }

  .invoice-page-shell .invoice-doc-header h1 {
    font-size: 20px;
  }

  .invoice-page-shell .invoice-doc-header h2,
  .invoice-page-shell h3 {
    font-size: 12px;
  }

  .invoice-page-shell .invoice-doc-header p,
  .invoice-page-shell .invoice-doc-grid p,
  .invoice-page-shell small {
    font-size: 9px;
    line-height: 1.35;
  }

  .invoice-page-shell .amount-words {
    border-radius: 10px;
    padding: 8px;
  }

  .invoice-page-shell .summary-box {
    gap: 6px;
  }

  .invoice-page-shell .invoice-summary {
    grid-template-columns: 1fr minmax(112px, 0.56fr);
  }

  .invoice-page-shell .summary-box .grand {
    font-size: 11px;
    padding-top: 7px;
  }

  .invoice-page-shell .data-table {
    display: table;
    min-width: 0;
    width: 100%;
    border-collapse: collapse;
  }

  .invoice-page-shell .data-table thead {
    display: table-header-group;
  }

  .invoice-page-shell .data-table tbody {
    display: table-row-group;
  }

  .invoice-page-shell .data-table tr {
    display: table-row;
    border: 0;
    border-radius: 0;
    padding: 0;
    margin-bottom: 0;
    background: transparent;
  }

  .invoice-page-shell .data-table th,
  .invoice-page-shell .data-table td {
    display: table-cell;
    width: auto;
    padding: 7px 5px;
    border-bottom: 1px solid rgba(81, 129, 155, 0.12);
    font-size: 9px;
  }

  .table-actions {
    padding-top: 8px;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
  }

  .table-actions .icon-button {
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
  }

  .table-actions form {
    display: inline-flex;
    margin: 0;
  }

  .form-actions,
  .action-bar {
    justify-content: stretch;
  }

  .form-actions .btn,
  .action-bar .btn,
  .sticky-actions .btn {
    flex: 1 1 100%;
    width: 100%;
  }

  .sticky-actions {
    left: 10px;
    right: 10px;
    bottom: 10px;
    display: grid;
    grid-template-columns: 1fr;
  }

  .details-list {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  .details-list dt {
    margin-top: 10px;
  }
}

@media print {
  body {
    background: #fff;
  }

  .sidebar,
  .topbar,
  .action-bar,
  .sticky-actions {
    display: none !important;
  }

  .app-layout,
  .main,
  .content {
    display: block;
    padding: 0;
  }

  .invoice-page-shell {
    overflow: visible;
    padding: 0;
  }

  .invoice-document {
    width: 100%;
    min-width: 0;
    box-shadow: none;
    border: 0;
    border-radius: 0;
    padding: 0;
  }

  .invoice-doc-header,
  .invoice-doc-grid {
    grid-template-columns: 1.4fr 1fr !important;
  }

  .invoice-summary {
    grid-template-columns: 1fr minmax(220px, 0.42fr) !important;
  }

  .invoice-doc-meta {
    text-align: right !important;
  }

  .invoice-document .data-table {
    display: table !important;
    min-width: 0;
    width: 100%;
    border-collapse: collapse;
  }

  .invoice-document .data-table thead {
    display: table-header-group !important;
  }

  .invoice-document .data-table tbody {
    display: table-row-group !important;
  }

  .invoice-document .data-table tr {
    display: table-row !important;
    border: 0;
    border-radius: 0;
    padding: 0;
    margin-bottom: 0;
    background: transparent;
  }

  .invoice-document .data-table th,
  .invoice-document .data-table td {
    display: table-cell !important;
    width: auto;
    padding: 13px 12px;
    border-bottom: 1px solid rgba(81, 129, 155, 0.12);
  }
}
