/* =================================================================
   SVG Editor -- Ribbon-style UI with Sidebar
   Uses OS skin colors via --sz-color-* custom properties
   ================================================================= */

/* ---- Base ---- */
* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--sz-color-button-face, #ece9d8);
  color: var(--sz-color-button-text, #1e1e1e);
  font: 11px Tahoma, "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
  user-select: none;
}

/* -- Tool Grid (4x2 in Home ribbon) ------------------------------ */

.tool-grid-4x2 {
  display: grid;
  grid-template-columns: repeat(4, 22px);
  gap: 1px;
}

.tool-grid-4x2 .rb-btn {
  width: 22px;
  height: 22px;
  padding: 0;
  font-size: 11px;
}

/* -- Ribbon inline inputs ---------------------------------------- */

.rb-inline-label {
  font-size: 10px;
  white-space: nowrap;
  min-width: 38px;
  display: inline;
  margin: 0;
}

.rb-color-input {
  width: 48px;
  height: 18px;
  padding: 0;
  border: 1px solid var(--sz-color-button-shadow, #888);
  cursor: default;
}

.rb-num-input {
  width: 52px;
  height: 18px;
  padding: 1px 2px;
  font-size: 10px;
  border: 1px solid var(--sz-color-button-shadow, #888);
  background: var(--sz-color-window, #fff);
  color: var(--sz-color-window-text, #000);
}

/* ---- Main area ---- */
.main-area {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

/* ---- Workspace ---- */
.workspace {
  flex: 1;
  overflow: auto;
  background:
    linear-gradient(45deg, #d0d0d0 25%, transparent 25%) 0 0/24px 24px,
    linear-gradient(-45deg, #d0d0d0 25%, transparent 25%) 0 0/24px 24px,
    linear-gradient(45deg, transparent 75%, #d0d0d0 75%) 0 0/24px 24px,
    linear-gradient(-45deg, transparent 75%, #d0d0d0 75%) 0 0/24px 24px,
    #e8e8e8;
  min-width: 0;
}

body.dark .workspace {
  background:
    linear-gradient(45deg, #333 25%, transparent 25%) 0 0/24px 24px,
    linear-gradient(-45deg, #333 25%, transparent 25%) 0 0/24px 24px,
    linear-gradient(45deg, transparent 75%, #333 75%) 0 0/24px 24px,
    linear-gradient(-45deg, transparent 75%, #333 75%) 0 0/24px 24px,
    #2a2a2a;
}

.svg-host {
  padding: 20px;
  min-width: fit-content;
  min-height: fit-content;
  transform-origin: 0 0;
  position: relative;
}

#svgCanvas {
  background: #fff;
  border: 1px solid #444;
  display: block;
}

body.dark #svgCanvas {
  border-color: #666;
}

/* ---- Sidebar ---- */
.sidebar {
  width: 200px;
  min-width: 160px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--sz-color-button-face, #ece9d8);
  border-left: 1px solid var(--sz-color-button-shadow, #888);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 0 4px;
  scrollbar-gutter: stable;
}

.panel {
  border-bottom: 1px solid var(--sz-color-button-shadow, #888);
  padding: 0 6px 6px;
  margin: 0;
}

.panel-toggle {
  cursor: pointer;
  user-select: none;
  list-style: none;
  padding: 4px 0;
}

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

.panel-toggle h2 {
  display: inline;
  font-size: 10px;
  text-transform: uppercase;
  margin: 0;
  font-weight: bold;
  color: var(--sz-color-button-text, #1e1e1e);
}

.panel-toggle::before {
  content: '\25bc';
  display: inline-block;
  width: 12px;
  font-size: 8px;
  transition: transform 0.15s;
}

details:not([open]) > .panel-toggle::before {
  transform: rotate(-90deg);
}

.row {
  display: flex;
  gap: 4px;
  margin-top: 4px;
  flex-wrap: wrap;
}

.sidebar label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 3px;
  gap: 6px;
  font-size: 11px;
}

input[type="number"],
input[type="color"],
textarea {
  border: 1px solid var(--sz-color-button-shadow, #888);
  background: var(--sz-color-window, #fff);
  color: var(--sz-color-window-text, #000);
  font: inherit;
}

.sidebar input[type="number"] { width: 70px; }
.sidebar input[type="color"] { width: 70px; height: 18px; padding: 0; }

.sidebar button {
  border: 1px solid var(--sz-color-button-shadow, #888);
  padding: 2px 8px;
  background: var(--sz-color-button-face, #ece9d8);
  color: var(--sz-color-button-text, #1e1e1e);
  cursor: default;
  font: inherit;
}

.sidebar button:hover {
  background: var(--sz-color-button-highlight, #fff);
}

.sidebar button:active {
  border-style: inset;
}

/* ---- Layer list ---- */
.layer-list {
  max-height: 120px;
  overflow: auto;
  border: 1px solid var(--sz-color-button-shadow, #888);
  background: var(--sz-color-window, #fff);
  padding: 1px;
  margin-top: 4px;
}

.layer-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 4px;
  align-items: center;
  padding: 2px 4px;
  cursor: default;
  font-size: 10px;
  user-select: none;
}

.layer-item:hover {
  background: var(--sz-color-button-highlight, #f0f0f0);
}

.layer-item.active {
  background: var(--sz-color-highlight, #2a62db);
  color: var(--sz-color-highlight-text, #fff);
}

/* ---- Source panel ---- */
.panel textarea {
  width: 100%;
  height: 100px;
  resize: vertical;
  box-sizing: border-box;
  font: 10px Consolas, "Courier New", monospace;
  margin-top: 4px;
}

/* ---- Status bar ---- */
.status-bar {
  display: flex;
  align-items: center;
  padding: 2px 8px;
  background: var(--sz-color-button-face, #ece9d8);
  border-top: 1px solid var(--sz-color-button-shadow, #888);
  font-size: 10px;
  color: var(--sz-color-button-text, #1e1e1e);
  flex-shrink: 0;
  user-select: none;
  gap: 12px;
  min-height: 22px;
}

.status-section {
  white-space: nowrap;
}

.status-spacer { flex: 1; }

/* ---- Selection dash on selected SVG element ---- */
.sel {
  stroke: #2a62db !important;
  stroke-dasharray: 4 3;
}

/* ---- Resize handles ---- */
.handle {
  position: absolute;
  width: 8px;
  height: 8px;
  background: #fff;
  border: 1px solid #2a62db;
  z-index: 50;
  box-sizing: border-box;
}

.handle[data-pos="nw"] { cursor: nw-resize; }
.handle[data-pos="n"]  { cursor: n-resize; }
.handle[data-pos="ne"] { cursor: ne-resize; }
.handle[data-pos="e"]  { cursor: e-resize; }
.handle[data-pos="se"] { cursor: se-resize; }
.handle[data-pos="s"]  { cursor: s-resize; }
.handle[data-pos="sw"] { cursor: sw-resize; }
.handle[data-pos="w"]  { cursor: w-resize; }

/* ---- Shortcut table ---- */
.shortcut-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}

.shortcut-table th {
  text-align: left;
  border-bottom: 1px solid var(--sz-color-button-shadow, #888);
  padding: 2px 8px;
  font-weight: bold;
}

.shortcut-table td {
  padding: 2px 8px;
  border-bottom: 1px solid var(--sz-color-button-highlight, #eee);
}

.shortcut-table tr:hover td {
  background: var(--sz-color-button-highlight, #f0f0f0);
}

/* ---- Dark mode ---- */
body.dark {
  --dark-bg: #2b2b2b;
  --dark-text: #ccc;
}

body.dark #svgCanvas {
  background: #1e1e1e;
}

body.dark .handle {
  background: #333;
  border-color: #7aa3ff;
}
