:root {
  --excel-green: #0f7f3a;
  --grid-line: #d9d9d9;
  --panel-line: #cfcfcf;
  --sheet-bg: #ffffff;
  --ribbon-bg: #f3f3f3;
  --text: #1f2933;
  --muted: #5f6b76;
  --blue: #5b9bd5;
  --purple: #a58ad7;
  --green: #a9d18e;
  --orange: #f4b183;
  --red: #ff6f79;
  --gold: #ffd966;
  --cyan: #9dc3e6;
  --home: #c9b299;
  --teal: #70adbd;
  --yellow: #fff2cc;
  --gray: #d9e2ea;
  font-family: Arial, Helvetica, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: #111;
  font-size: 13px;
}

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

button {
  border: 1px solid #b8c6d5;
  background: linear-gradient(#ffffff, #edf4fb);
  color: #17456d;
  min-height: 28px;
  padding: 4px 10px;
  line-height: 1.15;
  white-space: normal;
  cursor: pointer;
}

button:hover {
  background: #dceefa;
}

button:active {
  transform: translateY(1px);
}

input,
select,
textarea {
  border: 1px solid #aebdcc;
  background: #fff;
  min-height: 28px;
  min-width: 0;
  width: 100%;
  padding: 4px 6px;
}

textarea {
  resize: vertical;
}

.app-shell {
  min-height: 100vh;
  background: #f8f8f8;
  display: flex;
  flex-direction: column;
}

.excel-topbar {
  background: var(--ribbon-bg);
  border-bottom: 1px solid var(--panel-line);
}

.title-strip {
  min-height: 32px;
  background: #f7f7f7;
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid #d4d4d4;
}

.brand-mark {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px 0 10px;
  min-width: 260px;
  border-right: 1px solid #d4d4d4;
  background: #fff;
}

.brand-logo {
  width: 26px;
  height: 24px;
  border: 1px solid #0f7f3a;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-items: end;
  gap: 2px;
  padding: 3px;
  background: #f7fff9;
}

.brand-logo i {
  display: block;
  background: var(--excel-green);
}

.brand-logo i:nth-child(1) {
  height: 8px;
}

.brand-logo i:nth-child(2) {
  height: 14px;
}

.brand-logo i:nth-child(3) {
  height: 18px;
  background: #2f9de0;
}

.brand-text {
  font-size: 12px;
  font-weight: 700;
  color: #17324d;
  white-space: nowrap;
}

.file-tab {
  width: 48px;
  min-height: 32px;
  color: #fff;
  background: var(--excel-green);
  border: 0;
  text-transform: uppercase;
  font-weight: 700;
}

.menu-tabs {
  display: flex;
  gap: 2px;
  align-items: stretch;
  overflow-x: auto;
}

.menu-tabs button {
  border: 0;
  background: transparent;
  color: #111827;
  padding: 0 14px;
  min-height: 28px;
  text-transform: uppercase;
  font-size: 11px;
}

.menu-tabs button:hover {
  background: #e2e8f0;
}

.user-name {
  margin-left: auto;
  padding: 7px 18px 0 18px;
  font-size: 11px;
  white-space: nowrap;
}

.ribbon {
  display: grid;
  grid-template-columns: minmax(210px, .55fr) minmax(720px, 4.25fr) minmax(180px, .55fr) minmax(180px, .55fr);
  gap: 10px;
  padding: 8px;
  min-height: 98px;
  align-items: stretch;
}

.ribbon-group {
  border: 1px solid #d3d7dc;
  background: #f8f8f8;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
}

.ribbon-group > label {
  color: #52606d;
  font-size: 12px;
}

.ribbon-group > span {
  margin-top: auto;
  text-align: center;
  color: #64748b;
  font-size: 11px;
}

.inline-controls,
.button-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  min-width: 0;
}

.inline-controls button,
.button-grid button,
.task-form-grid button,
.dialog-actions button {
  width: 100%;
  max-width: 100%;
}

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

.task-form-grid {
  display: grid;
  grid-template-columns: minmax(140px, 1.45fr) minmax(92px, .75fr) minmax(104px, .72fr) minmax(104px, .72fr) minmax(82px, .55fr) minmax(92px, .65fr);
  gap: 4px;
  align-items: stretch;
  min-width: 0;
}

.task-form-grid > * {
  min-width: 0;
}

.task-form-grid input,
.task-form-grid select,
.task-form-grid button {
  min-height: 34px;
  padding-left: 4px;
  padding-right: 4px;
  font-size: 12px;
}

#taskDate,
#taskDue,
#taskProgress,
#taskComment {
  font-size: 11px;
}

#taskPriority,
#taskStatus,
#addTaskBtn {
  font-size: 11px;
}

#taskStatus {
  grid-column: 6;
  grid-row: 1;
}

#taskRepeat {
  grid-column: 1;
  grid-row: 2;
}

#taskProgress {
  grid-column: 2;
  grid-row: 2;
}

.comment-input {
  grid-column: 3 / 6;
  grid-row: 2;
}

.task-form-grid .primary-action {
  grid-column: 6;
  grid-row: 2;
  min-width: 0;
}

.primary-action {
  color: #fff;
  background: #2f9de0;
  border-color: #1977af;
}

.primary-action:hover {
  background: #238ed0;
}

.formula-row {
  display: grid;
  grid-template-columns: 90px 34px 1fr;
  align-items: center;
  height: 26px;
  border-top: 1px solid #e4e7eb;
  background: #fbfbfb;
}

.name-box,
.fx,
.formula-box {
  height: 100%;
  display: flex;
  align-items: center;
  border-right: 1px solid var(--panel-line);
  padding: 0 8px;
}

.fx {
  justify-content: center;
  font-style: italic;
  color: #1f4e79;
}

.formula-box {
  color: #425466;
}

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(620px, 1fr) minmax(330px, 38vw);
  gap: 8px;
  padding: 0 8px 8px;
  overflow: hidden;
}

.sheet-area,
.dashboard {
  background-color: var(--sheet-bg);
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 28px 24px;
  border: 1px solid var(--panel-line);
  min-height: 480px;
}

.sheet-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px 6px;
}

.note-title {
  margin: 0 0 6px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 16px;
  font-style: italic;
  color: #111827;
}

.note-text {
  margin: 0;
  color: #1f4e79;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 7px;
  background: rgba(255, 255, 255, .9);
  border: 1px solid var(--panel-line);
  font-size: 11px;
}

.legend-color {
  width: 14px;
  height: 10px;
  border: 1px solid rgba(0, 0, 0, .12);
}

.sheet-scroll {
  overflow: auto;
  max-height: calc(100vh - 238px);
  padding: 0 14px 14px;
}

.planner-table {
  border-collapse: collapse;
  min-width: 1060px;
  width: 100%;
  background: rgba(255, 255, 255, .82);
}

.planner-table th,
.planner-table td {
  border: 1px solid var(--grid-line);
  height: 28px;
  padding: 2px 4px;
  text-align: center;
  vertical-align: middle;
}

.planner-table th {
  background: #f6f8fa;
  font-weight: 700;
  color: #253858;
  position: sticky;
  top: 0;
  z-index: 2;
}

.row-number {
  width: 32px;
  color: #475569;
  background: #f8fafc;
}

.task-name-cell {
  width: 210px;
  min-width: 210px;
  text-align: left !important;
  position: sticky;
  left: 0;
  z-index: 1;
  background: #fff;
}

.task-name-cell strong {
  display: block;
  font-size: 12px;
  color: #111827;
  overflow-wrap: anywhere;
}

.task-name-cell span {
  display: inline-flex;
  margin-top: 3px;
  padding: 1px 5px;
  font-size: 10px;
  border-radius: 0;
  color: #1f2933;
}

.task-actions {
  width: 110px;
  min-width: 110px;
}

.mini-btn {
  min-height: 22px;
  padding: 1px 6px;
  font-size: 11px;
}

.day-cell {
  min-width: 28px;
  width: 28px;
  cursor: pointer;
  transition: outline .12s ease;
}

.day-cell:hover {
  outline: 2px solid #5b9bd5;
  outline-offset: -2px;
}

.day-cell.outside {
  background: #f7f7f7;
  cursor: default;
}

.day-cell.planned {
  box-shadow: inset 0 0 0 2px rgba(47, 157, 224, .22);
}

.mark-done {
  background: #c6efce !important;
}

.mark-partial {
  background: #ffeb9c !important;
}

.mark-missed {
  background: #f4b6c2 !important;
}

.mark-postponed {
  background: #d9e2ea !important;
}

.status-ready {
  color: #fff;
  background: var(--excel-green);
  padding: 4px 12px;
  text-transform: uppercase;
}

.dashboard {
  padding: 14px;
  overflow: auto;
}

.dashboard h1 {
  margin: 0 0 14px;
  text-align: center;
  font-size: 18px;
}

.dashboard h2 {
  margin: 0 0 10px;
  font-size: 14px;
  text-align: center;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  border: 1px solid var(--panel-line);
  background: rgba(255, 255, 255, .86);
  margin-bottom: 14px;
}

.stat-cell {
  min-height: 70px;
  border: 1px solid var(--grid-line);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.stat-cell strong {
  font-size: 24px;
  color: #1f4e79;
}

.stat-cell span {
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.chart-box,
.category-panel,
.year-panel {
  background: rgba(255, 255, 255, .9);
  border: 1px solid var(--panel-line);
  padding: 12px;
  margin-bottom: 14px;
}

.chart {
  height: 230px;
  display: grid;
  grid-template-columns: repeat(4, minmax(50px, 1fr));
  gap: 14px;
  align-items: end;
  border-left: 1px solid #d5dce3;
  border-bottom: 1px solid #d5dce3;
  background:
    linear-gradient(#e8edf3 1px, transparent 1px) 0 0 / 100% 20%;
  padding: 8px 8px 0;
}

.bar-group {
  min-height: 1px;
  display: flex;
  align-items: end;
  justify-content: center;
  gap: 2px;
  position: relative;
}

.bar {
  width: 22px;
  min-height: 4px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  font-size: 10px;
  color: #253858;
  padding-top: 3px;
}

.bar.done {
  background: var(--green);
}

.bar.late {
  background: var(--red);
}

.bar.process {
  background: var(--yellow);
}

.bar.postponed {
  background: var(--gray);
}

.bar-label {
  position: absolute;
  bottom: -26px;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  text-align: center;
  font-size: 10px;
  color: #344054;
}

.chart-legend {
  display: flex;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 32px;
  font-size: 11px;
}

.chart-legend span,
.category-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.chart-legend i {
  width: 22px;
  height: 8px;
  display: inline-block;
}

.legend-done {
  background: var(--green);
}

.legend-late {
  background: var(--red);
}

.legend-process {
  background: var(--yellow);
}

.category-row {
  margin-bottom: 8px;
}

.category-name {
  width: 84px;
  font-size: 11px;
}

.progress-track {
  flex: 1;
  height: 14px;
  border: 1px solid #d5dce3;
  background: #f8fafc;
}

.progress-fill {
  height: 100%;
  min-width: 1px;
}

.category-value {
  width: 40px;
  text-align: right;
  font-size: 11px;
}

.year-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.year-month {
  border: 1px solid var(--grid-line);
  background: #fff;
  padding: 6px;
  min-height: 54px;
}

.year-month strong {
  display: block;
  margin-bottom: 4px;
  font-size: 11px;
}

.year-month span {
  display: block;
  font-size: 10px;
  color: var(--muted);
}

.bottom-bar {
  min-height: 46px;
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: end;
  background: #f8f8f8;
  border-top: 1px solid var(--panel-line);
}

.month-tabs {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  padding: 0 80px 0 80px;
}

.month-tab {
  min-width: 48px;
  min-height: 24px;
  border: 1px solid #bcccdc;
  border-bottom: 0;
  background: #fff;
  color: #1f2933;
  font-size: 11px;
}

.month-tab.active {
  outline: 2px solid #2f9de0;
  outline-offset: -2px;
  font-weight: 700;
}

.month-tab:nth-child(2n) {
  background: #f4b183;
}

.month-tab:nth-child(3n) {
  background: #ffd966;
}

.month-tab:nth-child(4n) {
  background: #a9d18e;
}

.month-tab:nth-child(5n) {
  background: #9dc3e6;
}

.month-tab.year-mode {
  background: #ff7c80;
}

.zoom {
  min-width: 90px;
  color: #fff;
  background: var(--excel-green);
  padding: 4px 12px;
  text-align: right;
}

.edit-dialog {
  border: 1px solid #94a3b8;
  padding: 0;
  width: min(520px, calc(100vw - 24px));
}

.edit-dialog::backdrop {
  background: rgba(15, 23, 42, .35);
}

.edit-dialog form {
  display: grid;
  gap: 8px;
  padding: 14px;
}

.edit-dialog h2 {
  margin: 0 0 6px;
  font-size: 16px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.category-work {
  background: var(--blue);
}

.category-personal {
  background: var(--purple);
}

.category-habit {
  background: var(--green);
}

.category-family {
  background: var(--orange);
}

.category-health {
  background: var(--red);
}

.category-finance {
  background: var(--gold);
}

.category-study {
  background: var(--cyan);
}

.category-home {
  background: var(--home);
}

.category-project {
  background: var(--teal);
}

@media (max-width: 1080px) {
  .ribbon {
    grid-template-columns: 1fr 1fr;
  }

  .ribbon-group.wide {
    grid-column: 1 / -1;
    order: 3;
  }

  .workspace {
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .sheet-scroll {
    max-height: none;
  }
}

@media (max-width: 720px) {
  body {
    font-size: 12px;
  }

  .title-strip {
    height: auto;
    flex-wrap: wrap;
  }

  .brand-mark {
    min-width: 100%;
    min-height: 38px;
    border-bottom: 1px solid #d4d4d4;
  }

  .brand-text {
    white-space: normal;
  }

  .file-tab {
    height: 32px;
  }

  .menu-tabs {
    order: 3;
    width: 100%;
  }

  .menu-tabs button {
    min-width: 92px;
  }

  .user-name {
    padding-top: 9px;
  }

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

  .ribbon-group.wide {
    grid-column: auto;
    order: initial;
  }

  .task-form-grid {
    grid-template-columns: 1fr 1fr;
  }

  #taskStatus,
  #taskRepeat,
  #taskProgress {
    grid-column: auto;
    grid-row: auto;
  }

  .comment-input {
    grid-column: 1 / -1;
    grid-row: auto;
  }

  .task-form-grid .primary-action {
    grid-column: 1 / -1;
    grid-row: auto;
    min-width: 0;
  }

  .formula-row {
    grid-template-columns: 72px 28px minmax(180px, 1fr);
    overflow-x: auto;
  }

  .workspace {
    padding: 0 4px 8px;
  }

  .sheet-toolbar {
    flex-direction: column;
  }

  .legend {
    justify-content: flex-start;
  }

  .planner-table {
    min-width: 940px;
  }

  .dashboard {
    padding: 10px;
  }

  .chart {
    grid-template-columns: repeat(2, minmax(80px, 1fr));
    height: 280px;
    row-gap: 34px;
  }

  .year-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .bottom-bar {
    grid-template-columns: 1fr;
  }

  .month-tabs {
    padding: 0 4px;
  }

  .status-ready,
  .zoom {
    display: none;
  }
}

@media print {
  body,
  .app-shell {
    background: #fff;
  }

  .ribbon,
  .formula-row,
  .bottom-bar,
  .task-actions,
  .edit-dialog {
    display: none !important;
  }

  .workspace {
    display: block;
    padding: 0;
  }

  .sheet-scroll {
    max-height: none;
    overflow: visible;
  }

  .dashboard {
    page-break-before: always;
  }
}
