/* ============ THEME ============ */
:root {
  --lc-primary: #0f4c3a;
  --lc-primary-600: #0d4433;
  --lc-primary-700: #0a362a;
  --lc-accent: #c9a227;
  --lc-accent-soft: #f6ecc4;
  --lc-bg: #f5f7f6;
  --lc-card: #ffffff;
  --lc-text: #14221a;
  --lc-muted: #6b7a72;
  --lc-border: #e4e8e6;
  --lc-danger: #b3261e;
  --lc-urgent: #d8352d;
  --lc-high: #d97706;
  --lc-shadow-sm: 0 1px 3px rgba(15, 30, 20, .06);
  --lc-shadow: 0 6px 24px rgba(15, 30, 20, .08);
  --lc-shadow-lg: 0 20px 48px rgba(15, 30, 20, .16);
  --bs-body-font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

* { -webkit-tap-highlight-color: transparent; }

/* Bootstrap brand overrides */
.btn-primary {
  --bs-btn-bg: var(--lc-primary);
  --bs-btn-border-color: var(--lc-primary);
  --bs-btn-hover-bg: var(--lc-primary-600);
  --bs-btn-hover-border-color: var(--lc-primary-600);
  --bs-btn-active-bg: var(--lc-primary-700);
  --bs-btn-active-border-color: var(--lc-primary-700);
  --bs-btn-focus-shadow-rgb: 15, 76, 58;
  --bs-btn-disabled-bg: var(--lc-primary);
  --bs-btn-disabled-border-color: var(--lc-primary);
}
.btn-outline-secondary {
  --bs-btn-color: var(--lc-text);
  --bs-btn-border-color: var(--lc-border);
  --bs-btn-hover-bg: #eef2f0;
  --bs-btn-hover-border-color: var(--lc-border);
  --bs-btn-hover-color: var(--lc-text);
}
.nav-pills {
  --bs-nav-pills-link-active-bg: var(--lc-primary);
  --bs-nav-pills-link-active-color: #fff;
}
.nav-pills .nav-link { color: var(--lc-muted); font-weight: 500; }
.text-primary { color: var(--lc-primary) !important; }
.bg-primary { background-color: var(--lc-primary) !important; }

:focus-visible {
  outline: 2px solid var(--lc-primary);
  outline-offset: 2px;
  box-shadow: none;
}

/* ============ ROOT SHELL ============ */
html, body {
  height: 100%;
  overflow: hidden;
}
body.app-bg {
  background:
    radial-gradient(1200px 500px at 100% -10%, rgba(15,76,58,.08), transparent 60%),
    radial-gradient(900px 400px at -10% 110%, rgba(201,162,39,.10), transparent 60%),
    var(--lc-bg);
  color: var(--lc-text);
  height: 100dvh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
  font-feature-settings: "ss01";
}

.auth-view {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  overflow-y: auto;
  flex: 1;
}
.view { padding: 0; }

.app-shell {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.app-topbar { flex: 0 0 auto; }

/* ============ AUTH ============ */
.auth-card {
  width: 100%;
  max-width: 460px;
  border-radius: 20px;
  background: var(--lc-card);
  animation: rise .4s cubic-bezier(.2,.9,.3,1);
}
@keyframes rise {
  from { opacity: 0; transform: translateY(12px) scale(.98); }
  to   { opacity: 1; transform: none; }
}
.brand-mark {
  width: 64px; height: 64px;
  border-radius: 18px;
  display: grid; place-items: center;
  color: #fff; font-size: 30px;
  background: linear-gradient(135deg, var(--lc-primary), #1a6b52);
  box-shadow: 0 8px 24px rgba(15,76,58,.35);
}
.form-floating > .form-control:focus,
.form-floating > .form-control:not(:placeholder-shown) {
  border-color: var(--lc-primary);
  box-shadow: 0 0 0 .2rem rgba(15,76,58,.15);
}

/* ============ TOPBAR ============ */
.app-topbar {
  position: sticky; top: 0; z-index: 1030;
  background: rgba(255,255,255,.85);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--lc-border);
}
.brand-chip {
  width: 38px; height: 38px;
  border-radius: 12px;
  display: grid; place-items: center;
  color: #fff; font-size: 18px;
  background: linear-gradient(135deg, var(--lc-primary), #1a6b52);
  box-shadow: 0 4px 12px rgba(15,76,58,.28);
}
.btn-icon {
  width: 40px; height: 40px;
  display: inline-grid; place-items: center;
  border-radius: 12px;
  padding: 0;
  flex: 0 0 auto;
}
.btn-user {
  background: #fff;
  border: 1px solid var(--lc-border);
  border-radius: 999px;
  padding: 4px 12px 4px 4px;
  box-shadow: var(--lc-shadow-sm);
}
.avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  display: inline-grid; place-items: center;
  background: linear-gradient(135deg, var(--lc-primary), #1a6b52);
  color: #fff; font-weight: 600; font-size: 13px;
  flex: 0 0 auto;
}

/* ============ MAIN AREA ============ */
.app-main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: .6rem .75rem;
  gap: .6rem;
  overflow: hidden;
}
.app-toolbar { flex: 0 0 auto; }

/* ============ SPLIT LAYOUT ============ */
.app-split {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  gap: .6rem;
  grid-template-rows: minmax(0, 3fr) minmax(0, 2fr);
  grid-template-columns: 1fr;
  grid-template-areas:
    "calendar"
    "today";
}
.panel-calendar { grid-area: calendar; min-height: 0; min-width: 0; }
.panel-today    { grid-area: today;    min-height: 0; min-width: 0; }

.panel {
  display: flex;
  flex-direction: column;
  background: var(--lc-card);
  border-radius: 14px;
  box-shadow: var(--lc-shadow-sm);
  border: 1px solid var(--lc-border);
  overflow: hidden;
  min-height: 0;
}
.panel-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  padding: .5rem .75rem;
  border-bottom: 1px solid var(--lc-border);
  background: #fafbfa;
}
.panel-title {
  margin: 0;
  font-size: .85rem;
  font-weight: 600;
  color: var(--lc-text);
  display: flex;
  align-items: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.legend {
  display: flex;
  align-items: center;
  gap: .35rem;
  font-size: .7rem;
  color: var(--lc-muted);
}
.legend .legend-dot { width: 7px; height: 7px; border-radius: 50%; }
.legend-dot.chamber { background: var(--lc-primary); }
.legend-dot.personal { background: var(--lc-accent); }

/* ============ CALENDAR ============ */
.calendar-card {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.calendar-grid {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-template-rows: auto repeat(6, minmax(0, 1fr));
  min-height: 0;
  min-width: 0;
}
.cal-dow {
  padding: 4px 2px;
  text-align: center;
  font-size: clamp(9px, 1.4vmin, 11px);
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--lc-muted);
  background: #f6f8f7;
  border-bottom: 1px solid var(--lc-border);
  font-weight: 600;
  overflow: hidden;
}
.cal-day {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: clamp(2px, .6vmin, 5px);
  border-right: 1px solid var(--lc-border);
  border-bottom: 1px solid var(--lc-border);
  background: #fff;
  cursor: pointer;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  transition: background .15s;
  container-type: size;
}
.cal-day:nth-child(7n) { border-right: none; }
.cal-day:hover { background: #f7faf8; }
.cal-day:active { background: #eef4f1; }
.cal-day.other-month { color: #c3ccc7; cursor: default; background: #fbfcfb; }
.cal-day.other-month:hover { background: #fbfcfb; }
.cal-day.selected {
  outline: 2px solid var(--lc-primary);
  outline-offset: -2px;
  background: #eaf3ef;
}
.cal-day .num {
  font-weight: 600;
  font-size: clamp(10px, 2vmin, 14px);
  line-height: 1;
  flex: 0 0 auto;
}
.cal-day.today .num {
  background: var(--lc-primary);
  color: #fff;
  border-radius: 999px;
  width: clamp(19px, 4vmin, 25px);
  height: clamp(19px, 4vmin, 25px);
  display: inline-grid;
  place-items: center;
}
.cal-day .count-badge {
  position: absolute;
  top: 2px; right: 2px;
  background: var(--lc-primary);
  color: #fff;
  font-size: clamp(8px, 1.5vmin, 10px);
  line-height: 1;
  padding: 1px 4px;
  border-radius: 999px;
  font-weight: 600;
}
.cal-day .dots {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  margin-top: auto;
}
.cal-day .dot {
  width: clamp(4px, .9vmin, 6px);
  height: clamp(4px, .9vmin, 6px);
  border-radius: 50%;
  background: var(--lc-primary);
  flex: 0 0 auto;
}
.cal-day .dot.personal { background: var(--lc-accent); }

@container (max-width: 55px) { .cal-day .count-badge { display: none; } }
@container (max-width: 42px) { .cal-day .dots { display: none; } }
@container (max-height: 40px) { .cal-day .count-badge { display: none; } }
@container (max-height: 30px) {
  .cal-day .dots { display: none; }
  .cal-day .num { font-size: 10px; }
}
@container (max-height: 24px) { .cal-day .num { font-size: 9px; } }

/* ============ TODAY PANEL ============ */
.today-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: .6rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  -webkit-overflow-scrolling: touch;
}

.work-item {
  border: 1px solid var(--lc-border);
  border-left: 4px solid var(--lc-primary);
  border-radius: 10px;
  padding: .6rem .75rem;
  background: #fff;
  cursor: pointer;
  transition: transform .12s, box-shadow .15s;
  flex: 0 0 auto;
}
.work-item:hover {
  transform: translateY(-1px);
  box-shadow: var(--lc-shadow);
}
.work-item.personal { border-left-color: var(--lc-accent); }
.work-item .wi-title { font-weight: 600; font-size: .9rem; }
.work-item .wi-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  font-size: .75rem;
  color: var(--lc-muted);
  margin-top: 4px;
}
.work-item .wi-meta i { opacity: .7; }

.priority-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
  white-space: nowrap;
}
.priority-urgent { background: #fde8e6; color: var(--lc-urgent); }
.priority-high   { background: #fef3e2; color: var(--lc-high); }
.priority-normal { background: #e7f2ee; color: var(--lc-primary); }
.priority-low    { background: #eef1f0; color: var(--lc-muted); }

/* ============ EMPTY STATE ============ */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 1.5rem 1rem;
  color: var(--lc-muted);
  gap: .4rem;
}
.empty-state i { font-size: 2rem; opacity: .35; }
.empty-state .small { font-size: .85rem; }

/* ============ LANDSCAPE — SIDE BY SIDE ============ */
@media (min-width: 900px),
       (orientation: landscape) and (min-height: 380px) and (min-width: 600px) {
  .app-split {
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    grid-template-areas: "calendar today";
  }
}
@media (min-width: 1400px) {
  .app-split {
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  .app-main { padding: .4rem .6rem; gap: .4rem; }
  .panel-head { padding: .35rem .6rem; }
  .panel-title { font-size: .8rem; }
  .today-scroll { padding: .4rem; gap: .35rem; }
  .work-item { padding: .5rem .6rem; }
  .work-item .wi-title { font-size: .85rem; }
  .work-item .wi-meta { font-size: .7rem; }
}

@media (orientation: portrait) and (max-width: 576px) {
  .app-main { padding: .45rem .5rem; gap: .45rem; }
  .panel-head { padding: .4rem .6rem; }
  .today-scroll { padding: .5rem; gap: .4rem; }
}

@media (orientation: portrait) and (max-height: 640px) {
  .app-split { grid-template-rows: minmax(0, 5fr) minmax(0, 4fr); }
}

@media (min-width: 900px) and (min-height: 900px) {
  .app-main { max-width: 1600px; margin: 0 auto; width: 100%; }
}

/* ============ FAB ============ */
.fab {
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  width: 52px; height: 52px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 22px;
  z-index: 1040;
  box-shadow: 0 10px 28px rgba(15,76,58,.35);
}
@media (orientation: landscape) {
  .fab { display: none !important; }
}

/* ============ DETAIL MODAL ============ */
.detail-head {
  background: linear-gradient(135deg, var(--lc-primary), #1a6b52);
  color: #fff;
  border-bottom: 0;
  flex-wrap: wrap;
}
.detail-head .btn-close { filter: invert(1) brightness(2); }
.detail-head .modal-title { font-weight: 700; }
.detail-head .badge.text-bg-light { background: rgba(255,255,255,.92) !important; color: var(--lc-text); }

.detail-body { padding: 1rem 1rem 1.25rem; }
.detail-body .kv {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 8px 16px;
  font-size: 15px;
}
@media (max-width: 420px) {
  .detail-body .kv { grid-template-columns: 1fr; gap: 2px; }
  .detail-body .kv dt { margin-top: 8px; }
}
.detail-body .kv dt {
  color: var(--lc-muted);
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.detail-body .kv dd { margin: 0; }
.detail-body section + section {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px dashed var(--lc-border);
}

/* Image preview — contained, no overflow */
.attachment-preview {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: #eef1ef;
  cursor: zoom-in;
  aspect-ratio: 4 / 3;
  max-height: 320px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.attachment-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  transition: transform .2s;
}
.attachment-preview:hover img { transform: scale(1.02); }
.attachment-preview .zoom-hint {
  position: absolute;
  bottom: 8px; right: 8px;
  background: rgba(0,0,0,.6);
  color: #fff;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 4px;
  pointer-events: none;
}

/* ============ TYPE PICKER ============ */
.type-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.type-chip {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1.5px solid var(--lc-border);
  background: #fff;
  cursor: pointer;
  font-size: 12px;
  color: var(--lc-muted);
  transition: all .15s;
  user-select: none;
  min-width: 76px;
}
.type-chip i { font-size: 20px; }
.type-chip:hover { border-color: var(--lc-primary); color: var(--lc-primary); }
.btn-check:checked + .type-chip {
  border-color: var(--lc-primary);
  background: #eaf3ef;
  color: var(--lc-primary);
  font-weight: 600;
}
.btn-check:focus-visible + .type-chip { outline: 2px solid var(--lc-primary); outline-offset: 2px; }

/* ============ TOAST ============ */
.toast { border-radius: 12px; background: #14221a; color: #fff; }
.toast .toast-body { color: #fff; }

/* ============ MODAL BASE ============ */
.modal-content { border-radius: 16px; }

/* Smooth modal open */
.modal.fade .modal-dialog {
  transition: transform .25s cubic-bezier(.2,.9,.3,1), opacity .2s;
  transform: translateY(8px) scale(.98);
}
.modal.show .modal-dialog { transform: none; opacity: 1; }

/* Edit form: body scrolls, header/footer fixed */
.modal-form {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1 1 auto;
  overflow: hidden;
}
.modal-dialog-scrollable .modal-content { overflow: hidden; }
.modal-dialog-scrollable .modal-form .modal-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Fullscreen phone — modal body respects safe area & keyboard */
@media (max-width: 576px) {
  .modal-fullscreen-sm-down .modal-dialog {
    margin: 0;
    height: 100%;
    max-height: 100dvh;
  }
  .modal-fullscreen-sm-down .modal-content {
    border-radius: 16px 16px 0 0;
    height: 100%;
    max-height: 100dvh;
  }
  .modal-fullscreen-sm-down .modal-body {
    padding-bottom: calc(1rem + env(safe-area-inset-bottom));
  }
  .modal-fullscreen-sm-down .modal-footer {
    padding-bottom: calc(.75rem + env(safe-area-inset-bottom));
  }
}

/* Short landscape: cap modal to viewport */
@media (orientation: landscape) and (max-height: 500px) {
  .modal-dialog-scrollable .modal-content { max-height: calc(100dvh - 1rem); }
}

/* ============ FULLSCREEN IMAGE VIEWER ============ */
.image-viewer .modal-content { background: rgba(0,0,0,.92); }
.viewer-toolbar {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top));
  right: 12px;
  z-index: 10;
  display: flex;
  gap: 8px;
}
.viewer-stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 60px 12px 12px;
  touch-action: pinch-zoom;
}
.viewer-stage img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  transition: transform .15s ease;
  transform-origin: center center;
  user-select: none;
  -webkit-user-drag: none;
}

/* ============ SKELETON ============ */
.skeleton {
  background: linear-gradient(90deg, #eef1ef 25%, #f6f8f7 37%, #eef1ef 63%);
  background-size: 400% 100%;
  animation: shimmer 1.2s ease infinite;
  border-radius: 10px;
}
@keyframes shimmer {
  0%   { background-position: 100% 0; }
  100% { background-position: 0 0; }
}

/* ============ REDUCED MOTION ============ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}